mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
d17996f8b0
* Update V3 from V4 * Fix build v3 -> v4 * Update ssz * Update beacon_chain.pb.go * Fix formatter import * Update update-mockgen.sh comment to v4 * Fix conflicts. Pass build and tests * Fix test
37 lines
974 B
Go
37 lines
974 B
Go
package messagehandler_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/messagehandler"
|
|
"github.com/prysmaticlabs/prysm/v4/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"])
|
|
}
|
|
}
|