2018-08-12 20:27:21 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-05-09 21:02:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2018-08-12 20:27:21 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLifecycle(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
2018-11-25 16:55:02 +00:00
|
|
|
s, err := NewServer(&ServerConfig{})
|
2018-08-12 20:27:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not start a new server: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Start()
|
|
|
|
want := "Starting service"
|
2019-05-09 21:02:24 +00:00
|
|
|
testutil.AssertLogsContain(t, hook, want)
|
2018-08-12 20:27:21 +00:00
|
|
|
|
|
|
|
s.Stop()
|
2019-05-09 21:02:24 +00:00
|
|
|
msg := hook.LastEntry().Message
|
2018-08-12 20:27:21 +00:00
|
|
|
want = "Stopping service"
|
|
|
|
if msg != want {
|
|
|
|
t.Errorf("incorrect log. wanted: %s. got: %v", want, msg)
|
|
|
|
}
|
|
|
|
|
2019-04-26 06:24:01 +00:00
|
|
|
// The context should have been canceled.
|
2018-08-12 20:27:21 +00:00
|
|
|
if s.ctx.Err() == nil {
|
|
|
|
t.Error("Context was not cancelled")
|
|
|
|
}
|
|
|
|
}
|