|
|
@ -12,7 +12,6 @@ import ( |
|
|
|
libp2p_pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" |
|
|
|
libp2p_pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" |
|
|
|
|
|
|
|
|
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
mock "github.com/harmony-one/harmony/p2p/host/hostv2/mock" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func TestHostV2_SendMessageToGroups(t *testing.T) { |
|
|
|
func TestHostV2_SendMessageToGroups(t *testing.T) { |
|
|
@ -21,7 +20,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
groups := []nodeconfig.GroupID{"ABC", "DEF"} |
|
|
|
groups := []nodeconfig.GroupID{"ABC", "DEF"} |
|
|
|
data := []byte{1, 2, 3} |
|
|
|
data := []byte{1, 2, 3} |
|
|
|
pubsub := mock.NewMockpubsub(mc) |
|
|
|
pubsub := NewMockpubsub(mc) |
|
|
|
gomock.InOrder( |
|
|
|
gomock.InOrder( |
|
|
|
pubsub.EXPECT().Publish("ABC", data), |
|
|
|
pubsub.EXPECT().Publish("ABC", data), |
|
|
|
pubsub.EXPECT().Publish("DEF", data), |
|
|
|
pubsub.EXPECT().Publish("DEF", data), |
|
|
@ -36,7 +35,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
groups := []nodeconfig.GroupID{"ABC", "DEF"} |
|
|
|
groups := []nodeconfig.GroupID{"ABC", "DEF"} |
|
|
|
data := []byte{1, 2, 3} |
|
|
|
data := []byte{1, 2, 3} |
|
|
|
pubsub := mock.NewMockpubsub(mc) |
|
|
|
pubsub := NewMockpubsub(mc) |
|
|
|
gomock.InOrder( |
|
|
|
gomock.InOrder( |
|
|
|
pubsub.EXPECT().Publish("ABC", data).Return(errors.New("FIAL")), |
|
|
|
pubsub.EXPECT().Publish("ABC", data).Return(errors.New("FIAL")), |
|
|
|
pubsub.EXPECT().Publish("DEF", data), // Should not early-return
|
|
|
|
pubsub.EXPECT().Publish("DEF", data), // Should not early-return
|
|
|
@ -51,7 +50,7 @@ func TestHostV2_SendMessageToGroups(t *testing.T) { |
|
|
|
func TestGroupReceiver_Close(t *testing.T) { |
|
|
|
func TestGroupReceiver_Close(t *testing.T) { |
|
|
|
mc := gomock.NewController(t) |
|
|
|
mc := gomock.NewController(t) |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
sub := mock.NewMocksubscription(mc) |
|
|
|
sub := NewMocksubscription(mc) |
|
|
|
sub.EXPECT().Cancel() |
|
|
|
sub.EXPECT().Cancel() |
|
|
|
receiver := GroupReceiverImpl{sub: sub} |
|
|
|
receiver := GroupReceiverImpl{sub: sub} |
|
|
|
if err := receiver.Close(); err != nil { |
|
|
|
if err := receiver.Close(); err != nil { |
|
|
@ -67,7 +66,7 @@ func pubsubMessage(from libp2p_peer.ID, data []byte) *libp2p_pubsub.Message { |
|
|
|
func TestGroupReceiver_Receive(t *testing.T) { |
|
|
|
func TestGroupReceiver_Receive(t *testing.T) { |
|
|
|
mc := gomock.NewController(t) |
|
|
|
mc := gomock.NewController(t) |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
sub := mock.NewMocksubscription(mc) |
|
|
|
sub := NewMocksubscription(mc) |
|
|
|
ctx := context.Background() |
|
|
|
ctx := context.Background() |
|
|
|
gomock.InOrder( |
|
|
|
gomock.InOrder( |
|
|
|
sub.EXPECT().Next(ctx).Return(pubsubMessage("ABC", []byte{1, 2, 3}), nil), |
|
|
|
sub.EXPECT().Next(ctx).Return(pubsubMessage("ABC", []byte{1, 2, 3}), nil), |
|
|
@ -101,7 +100,7 @@ func TestHostV2_GroupReceiver(t *testing.T) { |
|
|
|
mc := gomock.NewController(t) |
|
|
|
mc := gomock.NewController(t) |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
sub := &libp2p_pubsub.Subscription{} |
|
|
|
sub := &libp2p_pubsub.Subscription{} |
|
|
|
pubsub := mock.NewMockpubsub(mc) |
|
|
|
pubsub := NewMockpubsub(mc) |
|
|
|
pubsub.EXPECT().Subscribe("ABC").Return(sub, nil) |
|
|
|
pubsub.EXPECT().Subscribe("ABC").Return(sub, nil) |
|
|
|
host := &HostV2{pubsub: pubsub} |
|
|
|
host := &HostV2{pubsub: pubsub} |
|
|
|
gotReceiver, err := host.GroupReceiver("ABC") |
|
|
|
gotReceiver, err := host.GroupReceiver("ABC") |
|
|
@ -117,7 +116,7 @@ func TestHostV2_GroupReceiver(t *testing.T) { |
|
|
|
t.Run("Error", func(t *testing.T) { |
|
|
|
t.Run("Error", func(t *testing.T) { |
|
|
|
mc := gomock.NewController(t) |
|
|
|
mc := gomock.NewController(t) |
|
|
|
defer mc.Finish() |
|
|
|
defer mc.Finish() |
|
|
|
pubsub := mock.NewMockpubsub(mc) |
|
|
|
pubsub := NewMockpubsub(mc) |
|
|
|
pubsub.EXPECT().Subscribe("ABC").Return(nil, errors.New("FIAL")) |
|
|
|
pubsub.EXPECT().Subscribe("ABC").Return(nil, errors.New("FIAL")) |
|
|
|
host := &HostV2{pubsub: pubsub} |
|
|
|
host := &HostV2{pubsub: pubsub} |
|
|
|
gotReceiver, err := host.GroupReceiver("ABC") |
|
|
|
gotReceiver, err := host.GroupReceiver("ABC") |
|
|
|