mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 19:51:20 +00:00
f5e5287082
Former-commit-id: 2ec35880b3aa30d3c217815c9a474e8d81ee1fa8 [formerly c20da02cf9149990f8b7913cfe426b8036992c16] Former-commit-id: 4851374829557f1523f5994b1d97e08e46979aed
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package observer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/database"
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/params"
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/syncer"
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/types"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
// Verifies that Observer implements the Actor interface.
|
|
var _ = types.Actor(&Observer{})
|
|
|
|
func TestStartStop(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
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
|
|
client := &mainchain.SMCClient{}
|
|
|
|
syncer, err := syncer.NewSyncer(params.DefaultConfig, client, server, shardChainDB, shardID)
|
|
if err != nil {
|
|
t.Fatalf("Unable to setup sync service: %v", err)
|
|
}
|
|
|
|
observer, err := NewObserver(server, shardChainDB, shardID, syncer, client)
|
|
if err != nil {
|
|
t.Fatalf("Unable to set up observer service: %v", err)
|
|
}
|
|
|
|
observer.sync.Start()
|
|
msg := hook.LastEntry().Message
|
|
if msg != "Starting sync service" {
|
|
t.Errorf("incorrect log, expected %s, got %s", "Starting sync service", msg)
|
|
}
|
|
|
|
observer.Start()
|
|
msg = hook.LastEntry().Message
|
|
if msg != "Starting observer service" {
|
|
t.Errorf("incorrect log, expected %s, got %s", "Starting observer service", msg)
|
|
}
|
|
|
|
err = observer.Stop()
|
|
if err != nil {
|
|
t.Fatalf("Unable to stop observer service: %v", err)
|
|
}
|
|
|
|
msg = hook.LastEntry().Message
|
|
if msg != "Stopping observer service" {
|
|
t.Errorf("incorrect log, expected %s, got %s", "Stopping observer service", msg)
|
|
}
|
|
|
|
if observer.ctx.Err() == nil {
|
|
t.Errorf("Context was not cancelled")
|
|
}
|
|
}
|