aboutsummaryrefslogtreecommitdiffstats
path: root/node/service_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-11-27 00:35:44 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-11-27 17:06:12 +0800
commit3e1000fda3424d880bc43ebbb16d8a33447d4182 (patch)
treefdc37470cba9af3a00e7eeaa02895b5166ddcd27 /node/service_test.go
parent1e806c4c775bd98b224eb0249007502d348e737b (diff)
downloaddexon-3e1000fda3424d880bc43ebbb16d8a33447d4182.tar.gz
dexon-3e1000fda3424d880bc43ebbb16d8a33447d4182.tar.zst
dexon-3e1000fda3424d880bc43ebbb16d8a33447d4182.zip
cmd, eth, node, rpc, xeth: use single-instance services
Diffstat (limited to 'node/service_test.go')
-rw-r--r--node/service_test.go37
1 files changed, 14 insertions, 23 deletions
diff --git a/node/service_test.go b/node/service_test.go
index 921a1a012..1dfb61f73 100644
--- a/node/service_test.go
+++ b/node/service_test.go
@@ -39,7 +39,7 @@ func TestContextDatabases(t *testing.T) {
}
// Request the opening/creation of a database and ensure it persists to disk
ctx := &ServiceContext{datadir: dir}
- db, err := ctx.Database("persistent", 0)
+ db, err := ctx.OpenDatabase("persistent", 0)
if err != nil {
t.Fatalf("failed to open persistent database: %v", err)
}
@@ -50,7 +50,7 @@ func TestContextDatabases(t *testing.T) {
}
// Request th opening/creation of an ephemeral database and ensure it's not persisted
ctx = &ServiceContext{datadir: ""}
- db, err = ctx.Database("ephemeral", 0)
+ db, err = ctx.OpenDatabase("ephemeral", 0)
if err != nil {
t.Fatalf("failed to open ephemeral database: %v", err)
}
@@ -67,36 +67,27 @@ func TestContextServices(t *testing.T) {
if err != nil {
t.Fatalf("failed to create protocol stack: %v", err)
}
- // Define a set of services, constructed before/after a verifier
- formers := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"}
- latters := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
-
+ // Define a verifier that ensures a NoopA is before it and NoopB after
verifier := func(ctx *ServiceContext) (Service, error) {
- for i, id := range formers {
- if ctx.Service(id) == nil {
- return nil, fmt.Errorf("former %d: service not found", i)
- }
+ var objA *NoopServiceA
+ if ctx.Service(&objA) != nil {
+ return nil, fmt.Errorf("former service not found")
}
- for i, id := range latters {
- if ctx.Service(id) != nil {
- return nil, fmt.Errorf("latters %d: service found", i)
- }
+ var objB *NoopServiceB
+ if err := ctx.Service(&objB); err != ErrServiceUnknown {
+ return nil, fmt.Errorf("latters lookup error mismatch: have %v, want %v", err, ErrServiceUnknown)
}
return new(NoopService), nil
}
// Register the collection of services
- for i, id := range formers {
- if err := stack.Register(id, NewNoopService); err != nil {
- t.Fatalf("former #%d: failed to register service: %v", i, err)
- }
+ if err := stack.Register(NewNoopServiceA); err != nil {
+ t.Fatalf("former failed to register service: %v", err)
}
- if err := stack.Register("verifier", verifier); err != nil {
+ if err := stack.Register(verifier); err != nil {
t.Fatalf("failed to register service verifier: %v", err)
}
- for i, id := range latters {
- if err := stack.Register(id, NewNoopService); err != nil {
- t.Fatalf("latter #%d: failed to register service: %v", i, err)
- }
+ if err := stack.Register(NewNoopServiceB); err != nil {
+ t.Fatalf("latter failed to register service: %v", err)
}
// Start the protocol stack and ensure services are constructed in order
if err := stack.Start(); err != nil {