prysm-pulse/sharding/observer/service_test.go
Raul Jordan f3f5b8e5a6 Simplify Service Registry, Pass in References as Dependencies to Prevent Nil Pointer Errors (#217)
sharding: simplify service registry to prevent nil pointer errors
Former-commit-id: ba4833c385e5212723932491810baad62e3ff0f9 [formerly c550c6d0837999f46a6de55a36fb1ae92d2ecd6f]
Former-commit-id: 80e9e13bc811444b461dad6bdf9eec633b911bec
2018-06-28 20:56:51 -04:00

50 lines
1.1 KiB
Go

package observer
import (
"testing"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/sharding"
"github.com/ethereum/go-ethereum/sharding/database"
internal "github.com/ethereum/go-ethereum/sharding/internal"
"github.com/ethereum/go-ethereum/sharding/p2p"
)
// Verifies that Observer implements the Actor interface.
var _ = sharding.Actor(&Observer{})
func TestStartStop(t *testing.T) {
h := internal.NewLogHandler(t)
log.Root().SetHandler(h)
server, err := p2p.NewServer()
if err != nil {
t.Fatalf("Unable to setup p2p server: %v", err)
}
shardChainDB, err := database.NewShardDB("", "", true)
if err != nil {
t.Fatalf("Unable to setup db: %v", err)
}
shardID := 0
observer, err := NewObserver(server, shardChainDB, shardID)
if err != nil {
t.Fatalf("Unable to set up observer service: %v", err)
}
observer.Start()
h.VerifyLogMsg("Starting observer service")
err = observer.Stop()
if err != nil {
t.Fatalf("Unable to stop observer service: %v", err)
}
h.VerifyLogMsg("Stopping observer service")
if observer.ctx.Err() == nil {
t.Errorf("Context was not cancelled")
}
}