mirror of https://github.com/status-im/go-waku.git
fix: race in TestConnectionStatusChanges (#257)
This commit is contained in:
parent
c93cda7a95
commit
8e295a2a57
|
@ -13,8 +13,12 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"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)
|
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()
|
defer wg.Done()
|
||||||
|
|
||||||
timeout := time.After(5 * time.Second)
|
timeout := time.After(5 * time.Second)
|
||||||
|
@ -85,31 +89,31 @@ func TestConnectionStatusChanges(t *testing.T) {
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
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())
|
err = node1.DialPeer(ctx, node2.ListenAddresses()[0].String())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
wg.Wait()
|
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())
|
err = node1.DialPeer(ctx, node3.ListenAddresses()[0].String())
|
||||||
require.NoError(t, err)
|
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()
|
node3.Stop()
|
||||||
|
|
||||||
wg.Wait()
|
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())
|
err = node1.ClosePeerById(node2.Host().ID())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
wg.Wait()
|
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())
|
err = node1.DialPeerByID(ctx, node2.Host().ID())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue