2018-06-06 02:38:16 +00:00
|
|
|
package observer
|
|
|
|
|
2018-06-20 03:59:02 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2018-07-07 17:23:19 +00:00
|
|
|
"github.com/prysmaticlabs/geth-sharding/sharding"
|
|
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/database"
|
|
|
|
"github.com/prysmaticlabs/geth-sharding/sharding/internal"
|
|
|
|
"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"
|
2018-06-20 03:59:02 +00:00
|
|
|
)
|
2018-06-06 02:38:16 +00:00
|
|
|
|
|
|
|
// Verifies that Observer implements the Actor interface.
|
|
|
|
var _ = sharding.Actor(&Observer{})
|
2018-06-20 03:59:02 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2018-06-29 00:56:51 +00:00
|
|
|
shardChainDB, err := database.NewShardDB("", "", true)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to setup db: %v", err)
|
|
|
|
}
|
2018-06-20 03:59:02 +00:00
|
|
|
shardID := 0
|
2018-07-07 17:23:19 +00:00
|
|
|
client := &mainchain.SMCClient{}
|
2018-06-20 03:59:02 +00:00
|
|
|
|
2018-07-07 17:23:19 +00:00
|
|
|
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)
|
2018-06-20 03:59:02 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to set up observer service: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-07-07 17:23:19 +00:00
|
|
|
observer.sync.Start()
|
|
|
|
h.VerifyLogMsg("Starting sync service")
|
2018-06-20 03:59:02 +00:00
|
|
|
|
2018-07-07 17:23:19 +00:00
|
|
|
observer.Start()
|
2018-06-20 03:59:02 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|