2019-10-04 22:46:49 +00:00
|
|
|
package messagehandler_test
|
2019-03-10 22:53:28 +00:00
|
|
|
|
|
|
|
import (
|
2019-03-17 02:56:05 +00:00
|
|
|
"context"
|
2019-03-10 22:53:28 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
2019-11-27 05:08:18 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-10-04 22:46:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/messagehandler"
|
2019-03-10 22:53:28 +00: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 22:46:49 +00:00
|
|
|
messagehandler.SafelyHandleMessage(nil, func(_ context.Context, _ proto.Message) error {
|
2019-03-10 22:53:28 +00:00
|
|
|
panic("bad!")
|
2019-03-17 02:56:05 +00:00
|
|
|
return nil
|
2019-07-22 14:03:57 +00:00
|
|
|
}, ðpb.BeaconBlock{})
|
2019-03-10 22:53:28 +00:00
|
|
|
|
|
|
|
testutil.AssertLogsContain(t, hook, "Panicked when handling p2p message!")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSafelyHandleMessage_NoData(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
|
2019-10-04 22:46:49 +00:00
|
|
|
messagehandler.SafelyHandleMessage(nil, func(_ context.Context, _ proto.Message) error {
|
2019-03-10 22:53:28 +00:00
|
|
|
panic("bad!")
|
2019-03-17 02:56:05 +00:00
|
|
|
return nil
|
2019-03-10 22:53:28 +00: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"])
|
|
|
|
}
|
|
|
|
}
|