From 8e295a2a575193f9f4217741e97a6dfc9d25b43d Mon Sep 17 00:00:00 2001 From: Martin Kobetic Date: Fri, 10 Jun 2022 08:15:00 -0400 Subject: [PATCH] fix: race in TestConnectionStatusChanges (#257) --- waku/v2/node/connectedness_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/waku/v2/node/connectedness_test.go b/waku/v2/node/connectedness_test.go index e3c5bd66..f502e553 100644 --- a/waku/v2/node/connectedness_test.go +++ b/waku/v2/node/connectedness_test.go @@ -13,8 +13,12 @@ import ( "github.com/stretchr/testify/require" ) -func checkConnectedness(t *testing.T, wg *sync.WaitGroup, connStatusChan chan ConnStatus, clientNode *WakuNode, node *WakuNode, nodeShouldBeConnected bool, shouldBeOnline bool, shouldHaveHistory bool, expectedPeers int) { +func goCheckConnectedness(t *testing.T, wg *sync.WaitGroup, connStatusChan chan ConnStatus, clientNode *WakuNode, node *WakuNode, nodeShouldBeConnected bool, shouldBeOnline bool, shouldHaveHistory bool, expectedPeers int) { wg.Add(1) + go checkConnectedness(t, wg, connStatusChan, clientNode, node, nodeShouldBeConnected, shouldBeOnline, shouldHaveHistory, expectedPeers) +} + +func checkConnectedness(t *testing.T, wg *sync.WaitGroup, connStatusChan chan ConnStatus, clientNode *WakuNode, node *WakuNode, nodeShouldBeConnected bool, shouldBeOnline bool, shouldHaveHistory bool, expectedPeers int) { defer wg.Done() timeout := time.After(5 * time.Second) @@ -85,31 +89,31 @@ func TestConnectionStatusChanges(t *testing.T) { var wg sync.WaitGroup - go checkConnectedness(t, &wg, connStatusChan, node1, node2, true, true, false, 1) + goCheckConnectedness(t, &wg, connStatusChan, node1, node2, true, true, false, 1) err = node1.DialPeer(ctx, node2.ListenAddresses()[0].String()) require.NoError(t, err) wg.Wait() - go checkConnectedness(t, &wg, connStatusChan, node1, node3, true, true, true, 2) + goCheckConnectedness(t, &wg, connStatusChan, node1, node3, true, true, true, 2) err = node1.DialPeer(ctx, node3.ListenAddresses()[0].String()) require.NoError(t, err) - go checkConnectedness(t, &wg, connStatusChan, node1, node3, false, true, false, 1) + goCheckConnectedness(t, &wg, connStatusChan, node1, node3, false, true, false, 1) node3.Stop() wg.Wait() - go checkConnectedness(t, &wg, connStatusChan, node1, node2, false, false, false, 0) + goCheckConnectedness(t, &wg, connStatusChan, node1, node2, false, false, false, 0) err = node1.ClosePeerById(node2.Host().ID()) require.NoError(t, err) wg.Wait() - go checkConnectedness(t, &wg, connStatusChan, node1, node2, true, true, false, 1) + goCheckConnectedness(t, &wg, connStatusChan, node1, node2, true, true, false, 1) err = node1.DialPeerByID(ctx, node2.Host().ID()) require.NoError(t, err)