From 7fddef3d6ff4aa7f9c7355608ffc86e1a1ca2b14 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 23 Apr 2020 15:33:42 +0300 Subject: [PATCH] add test for assorted pubsub options that were not covered --- floodsub_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/floodsub_test.go b/floodsub_test.go index e9905c4..fe8e251 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -3,6 +3,7 @@ package pubsub import ( "bytes" "context" + "crypto/sha256" "fmt" "io" "math/rand" @@ -1042,3 +1043,43 @@ func (aw *announceWatcher) countSubs() int { defer aw.mx.Unlock() return aw.subs } + +func TestPubsubWithAssortedOptions(t *testing.T) { + // this test uses assorted options that are not covered in other tests + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + hashMsgID := func(m *pb.Message) string { + hash := sha256.Sum256(m.Data) + return string(hash[:]) + } + + hosts := getNetHosts(t, ctx, 2) + psubs := getPubsubs(ctx, hosts, + WithMessageIdFn(hashMsgID), + WithPeerOutboundQueueSize(1), + WithMessageAuthor(""), + WithBlacklist(NewMapBlacklist())) + + connect(t, hosts[0], hosts[1]) + + var subs []*Subscription + for _, ps := range psubs { + sub, err := ps.Subscribe("test") + if err != nil { + t.Fatal(err) + } + subs = append(subs, sub) + } + + time.Sleep(100 * time.Millisecond) + + for i := 0; i < 2; i++ { + msg := []byte(fmt.Sprintf("message %d", i)) + psubs[i].Publish("test", msg) + + for _, sub := range subs { + assertReceive(t, sub, msg) + } + } +}