From 285c1f0aa74307696afb3eda92e1165d718b7ca0 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 21 Feb 2018 19:14:07 +0200 Subject: [PATCH] add test for graft/prune coalescing in heartbeat --- gossipsub_test.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gossipsub_test.go b/gossipsub_test.go index e21984d..2a86384 100644 --- a/gossipsub_test.go +++ b/gossipsub_test.go @@ -593,6 +593,54 @@ func TestGossipsubRemovePeer(t *testing.T) { } } +func TestGossipsubGraftPruneCoalesce(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + hosts := getNetHosts(t, ctx, 20) + psubs := getGossipsubs(ctx, hosts) + denseConnect(t, hosts) + + var topics []string + var msgs [][]*Subscription + for i := 0; i < 100; i++ { + topic := fmt.Sprintf("topic%d", i) + + var subs []*Subscription + for _, ps := range psubs { + subch, err := ps.Subscribe(topic) + if err != nil { + t.Fatal(err) + } + + subs = append(subs, subch) + } + + msgs = append(msgs, subs) + } + + // wait for heartbeats to build meshes + time.Sleep(time.Second * 2) + + for i, topic := range topics { + msg := []byte(fmt.Sprintf("%d it's not a floooooood %d", i, i)) + + owner := rand.Intn(len(psubs)) + + psubs[owner].Publish(topic, msg) + + for _, sub := range msgs[i] { + got, err := sub.Next(ctx) + if err != nil { + t.Fatal(sub.err) + } + if !bytes.Equal(msg, got.Data) { + t.Fatal("got wrong message!") + } + } + } +} + func TestMixedGossipsub(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel()