Skip to content

Commit

Permalink
make sure we're broadcasting different messages in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tok-kkk committed Nov 20, 2019
1 parent e4ea033 commit 3dff593
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ var _ = Describe("Peer", func() {
}
}

broadcastTest := func(ctx context.Context, peers []peer.Peer, events []chan protocol.Event) bool {
broadcastTest := func(ctx context.Context, peers []peer.Peer, events []chan protocol.Event, messageBody []byte) bool {
broadcastCtx, broadcastCancel := context.WithTimeout(ctx, 10*time.Second)
defer broadcastCancel()

sender := rand.Intn(len(peers))
messageBody := RandomMessageBody()
Expect(peers[sender].Broadcast(broadcastCtx, protocol.NilPeerGroupID, messageBody)).NotTo(HaveOccurred())

for i, event := range events {
Expand Down Expand Up @@ -133,8 +132,17 @@ var _ = Describe("Peer", func() {

// Expect multicast is working as expected
logrus.Print("Testing broadcast messages...")
messages := map[string]struct{}{}
broadcast := func() bool {
return broadcastTest(ctx, peers, events)
message := RandomMessageBody()
for {
if _, ok := messages[string(message)]; !ok {
break
}
message = RandomMessageBody()
}
messages[string(message)] = struct{}{}
return broadcastTest(ctx, peers, events, message)
}
Expect(quick.Check(broadcast, nil)).NotTo(HaveOccurred())
})
Expand Down
2 changes: 1 addition & 1 deletion testutil/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func RandomBytes(length int) []byte {
}

func RandomMessageBody() []byte {
length := rand.Intn(256)
length := rand.Intn(512)
return RandomBytes(length)
}

Expand Down

0 comments on commit 3dff593

Please sign in to comment.