prysm-pulse/beacon-chain/blockchain/service_test.go
Raul Jordan 92af8bc351 Rename Entire Project to Repo, Change Import Paths and Readmes (#298)
Former-commit-id: b7b8bbd10777012ae6f7d30eb6b05c3b1c3ec5d3 [formerly 06e1112fa0e1092a7137186d3a386972daa2effe]
Former-commit-id: ff2bc760c9dafb6250f056606eb2cbf96b6afa5b
2018-07-20 16:31:26 -05:00

64 lines
1.5 KiB
Go

package blockchain
import (
"context"
"fmt"
"os"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/database"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestStartStop(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
tmp := fmt.Sprintf("%s/beacontest", os.TempDir())
config := &database.BeaconDBConfig{DataDir: tmp, Name: "beacontestdata", InMemory: false}
db, err := database.NewBeaconDB(config)
if err != nil {
t.Fatalf("could not setup beaconDB: %v", err)
}
db.Start()
chainService, err := NewChainService(ctx, db)
if err != nil {
t.Fatalf("unable to setup chain service: %v", err)
}
chainService.Start()
if err := chainService.Stop(); err != nil {
t.Fatalf("unable to stop chain service: %v", err)
}
msg := hook.AllEntries()[0].Message
want := "Starting beaconDB service"
if msg != want {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}
msg = hook.AllEntries()[1].Message
want = "Starting blockchain service"
if msg != want {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}
msg = hook.AllEntries()[2].Message
want = "No chainstate found on disk, initializing beacon from genesis"
if msg != want {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}
msg = hook.AllEntries()[3].Message
want = "Stopping blockchain service"
if msg != want {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}
// The context should have been canceled.
if chainService.ctx.Err() == nil {
t.Error("context was not canceled")
}
hook.Reset()
}