2019-10-04 15:46:49 -07:00
|
|
|
package messagehandler_test
|
2019-03-11 06:53:28 +08:00
|
|
|
|
|
|
|
import (
|
2019-03-16 22:56:05 -04:00
|
|
|
"context"
|
2019-03-11 06:53:28 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
2019-11-26 23:08:18 -06:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-10-04 15:46:49 -07:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/messagehandler"
|
2019-03-11 06:53:28 +08:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
|
|
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSafelyHandleMessage(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
2019-10-04 15:46:49 -07:00
|
|
|
messagehandler.SafelyHandleMessage(nil, func(_ context.Context, _ proto.Message) error {
|
2019-03-11 06:53:28 +08:00
|
|
|
panic("bad!")
|
2019-03-16 22:56:05 -04:00
|
|
|
return nil
|
2019-07-22 07:03:57 -07:00
|
|
|
}, ðpb.BeaconBlock{})
|
2019-03-11 06:53:28 +08:00
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Panicked when handling p2p message!")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSafelyHandleMessage_NoData(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
2019-10-04 15:46:49 -07:00
|
|
|
messagehandler.SafelyHandleMessage(nil, func(_ context.Context, _ proto.Message) error {
|
2019-03-11 06:53:28 +08:00
|
|
|
panic("bad!")
|
2019-03-16 22:56:05 -04:00
|
|
|
return nil
|
2019-03-11 06:53:28 +08:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
entry := hook.LastEntry()
|
|
|
|
if entry.Data["msg"] != "message contains no data" {
|
|
|
|
t.Errorf("Message logged was not what was expected: %s", entry.Data["msg"])
|
|
|
|
}
|
|
|
|
}
|