From 68fe29c56fc5b9d42fcbf1d8234be0596b4a9aca Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 20 Oct 2021 14:43:51 -0400 Subject: [PATCH] test: broadcast (#94) --- waku/v2/node/broadcast_test.go | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 waku/v2/node/broadcast_test.go diff --git a/waku/v2/node/broadcast_test.go b/waku/v2/node/broadcast_test.go new file mode 100644 index 00000000..3ed35261 --- /dev/null +++ b/waku/v2/node/broadcast_test.go @@ -0,0 +1,46 @@ +package node + +import ( + "sync" + "testing" + + "github.com/status-im/go-waku/waku/v2/protocol" + "github.com/stretchr/testify/require" +) + +// Adapted from https://github.com/dustin/go-broadcast/commit/f664265f5a662fb4d1df7f3533b1e8d0e0277120 +// by Dustin Sallings (c) 2013, which was released under MIT license + +func TestBroadcast(t *testing.T) { + wg := sync.WaitGroup{} + + b := NewBroadcaster(100) + defer b.Close() + + for i := 0; i < 5; i++ { + wg.Add(1) + + cch := make(chan *protocol.Envelope) + + b.Register(cch) + + go func() { + defer wg.Done() + defer b.Unregister(cch) + <-cch + }() + + } + + env := new(protocol.Envelope) + b.Submit(env) + + wg.Wait() +} + +func TestBroadcastCleanup(t *testing.T) { + b := NewBroadcaster(100) + b.Register(make(chan *protocol.Envelope)) + err := b.Close() + require.NoError(t, err) +}