Rename GroupReceiver → GroupReceiverImpl in hostv2

Suggested-by: Minh Doan <minh@harmony.one>
pull/392/head
Eugene Kim 6 years ago
parent ed8b3c0a3f
commit 7f0e170f7a
  1. 10
      p2p/host/hostv2/hostv2.go
  2. 10
      p2p/host/hostv2/hostv2_test.go

@ -58,20 +58,20 @@ type Subscription interface {
Cancel() Cancel()
} }
// GroupReceiver is a multicast group receiver implementation. // GroupReceiverImpl is a multicast group receiver implementation.
type GroupReceiver struct { type GroupReceiverImpl struct {
sub Subscription sub Subscription
} }
// Close closes this receiver. // Close closes this receiver.
func (r *GroupReceiver) Close() error { func (r *GroupReceiverImpl) Close() error {
r.sub.Cancel() r.sub.Cancel()
r.sub = nil r.sub = nil
return nil return nil
} }
// Receive receives a message. // Receive receives a message.
func (r *GroupReceiver) Receive(ctx context.Context) ( func (r *GroupReceiverImpl) Receive(ctx context.Context) (
msg []byte, sender peer.ID, err error, msg []byte, sender peer.ID, err error,
) { ) {
m, err := r.sub.Next(ctx) m, err := r.sub.Next(ctx)
@ -91,7 +91,7 @@ func (host *HostV2) GroupReceiver(group p2p.GroupID) (
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &GroupReceiver{sub: sub}, nil return &GroupReceiverImpl{sub: sub}, nil
} }
// AddPeer add p2p.Peer into Peerstore // AddPeer add p2p.Peer into Peerstore

@ -54,7 +54,7 @@ func TestGroupReceiver_Close(t *testing.T) {
defer mc.Finish() defer mc.Finish()
sub := mock.NewMockSubscription(mc) sub := mock.NewMockSubscription(mc)
sub.EXPECT().Cancel() sub.EXPECT().Cancel()
receiver := GroupReceiver{sub: sub} receiver := GroupReceiverImpl{sub: sub}
if err := receiver.Close(); err != nil { if err := receiver.Close(); err != nil {
t.Errorf("expected no error but got %v", err) t.Errorf("expected no error but got %v", err)
} }
@ -75,7 +75,7 @@ func TestGroupReceiver_Receive(t *testing.T) {
sub.EXPECT().Next(ctx).Return(pubsubMessage("DEF", []byte{4, 5, 6}), nil), sub.EXPECT().Next(ctx).Return(pubsubMessage("DEF", []byte{4, 5, 6}), nil),
sub.EXPECT().Next(ctx).Return(nil, errors.New("FIAL")), sub.EXPECT().Next(ctx).Return(nil, errors.New("FIAL")),
) )
receiver := GroupReceiver{sub: sub} receiver := GroupReceiverImpl{sub: sub}
verify := func(sender peer.ID, msg []byte, shouldError bool) { verify := func(sender peer.ID, msg []byte, shouldError bool) {
gotMsg, gotSender, err := receiver.Receive(ctx) gotMsg, gotSender, err := receiver.Receive(ctx)
if (err != nil) != shouldError { if (err != nil) != shouldError {
@ -106,8 +106,8 @@ func TestHostV2_GroupReceiver(t *testing.T) {
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")
if r, ok := gotReceiver.(*GroupReceiver); !ok { if r, ok := gotReceiver.(*GroupReceiverImpl); !ok {
t.Errorf("expected a hostv2 GroupReceiver; got %v", gotReceiver) t.Errorf("expected a hostv2 GroupReceiverImpl; got %v", gotReceiver)
} else if r.sub != sub { } else if r.sub != sub {
t.Errorf("unexpected subscriber %v", r.sub) t.Errorf("unexpected subscriber %v", r.sub)
} }
@ -123,7 +123,7 @@ func TestHostV2_GroupReceiver(t *testing.T) {
host := &HostV2{pubsub: pubsub} host := &HostV2{pubsub: pubsub}
gotReceiver, err := host.GroupReceiver("ABC") gotReceiver, err := host.GroupReceiver("ABC")
if gotReceiver != nil { if gotReceiver != nil {
t.Errorf("expected a nil hostv2 GroupReceiver; got %v", gotReceiver) t.Errorf("expected a nil hostv2 GroupReceiverImpl; got %v", gotReceiver)
} }
if err == nil { if err == nil {
t.Error("expected an error; got none") t.Error("expected an error; got none")

Loading…
Cancel
Save