From 553394944333283fab89200bf7c88a2c46738e79 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 21 Feb 2018 13:53:31 +0200 Subject: [PATCH] finetune gossip test, add join grafting test --- gossipsub_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/gossipsub_test.go b/gossipsub_test.go index 28ae3b3..00b9184 100644 --- a/gossipsub_test.go +++ b/gossipsub_test.go @@ -127,7 +127,7 @@ func TestGossipsubGossip(t *testing.T) { // wait for heartbeats to build mesh time.Sleep(time.Second * 2) - for i := 0; i < 10; i++ { + for i := 0; i < 100; i++ { msg := []byte(fmt.Sprintf("%d it's not a floooooood %d", i, i)) owner := rand.Intn(len(psubs)) @@ -144,8 +144,8 @@ func TestGossipsubGossip(t *testing.T) { } } - // wait for hearbeat to have some gossip - time.Sleep(time.Second * 1) + // wait a bit to have some gossip interleaved + time.Sleep(time.Millisecond * 100) } // and wait for some gossip flushing @@ -201,6 +201,51 @@ func TestGossipsubPrune(t *testing.T) { } } +func TestGossipsubGraft(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + hosts := getNetHosts(t, ctx, 20) + + psubs := getGossipsubs(ctx, hosts) + + sparseConnect(t, hosts) + + time.Sleep(time.Second * 1) + + var msgs []*Subscription + for _, ps := range psubs { + subch, err := ps.Subscribe("foobar") + if err != nil { + t.Fatal(err) + } + + msgs = append(msgs, subch) + + // wait for announce to propagate + time.Sleep(time.Millisecond * 100) + } + + time.Sleep(time.Second * 1) + + for i := 0; i < 100; i++ { + msg := []byte(fmt.Sprintf("%d it's not a floooooood %d", i, i)) + + owner := rand.Intn(len(psubs)) + + psubs[owner].Publish("foobar", msg) + + for _, sub := range msgs { + 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()