prysm-pulse/runtime/messagehandler/messagehandler_test.go
terence 5a66807989
Update to V5 (#13622)
* First take at updating everything to v5

* Patch gRPC gateway to use prysm v5

Fix patch

* Update go ssz

---------

Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
2024-02-15 05:46:47 +00:00

37 lines
974 B
Go

package messagehandler_test
import (
"context"
"testing"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/prysmaticlabs/prysm/v5/runtime/messagehandler"
"github.com/prysmaticlabs/prysm/v5/testing/require"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestSafelyHandleMessage(t *testing.T) {
hook := logTest.NewGlobal()
messagehandler.SafelyHandleMessage(context.Background(), func(_ context.Context, _ *pubsub.Message) error {
panic("bad!")
return nil
}, &pubsub.Message{})
require.LogsContain(t, hook, "Panicked when handling p2p message!")
}
func TestSafelyHandleMessage_NoData(t *testing.T) {
hook := logTest.NewGlobal()
messagehandler.SafelyHandleMessage(context.Background(), func(_ context.Context, _ *pubsub.Message) error {
panic("bad!")
return nil
}, 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"])
}
}