Commit 3952e601 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-e2e: Fix hanging network notify test (#12868)

parent b1efd7c5
...@@ -360,18 +360,24 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) { ...@@ -360,18 +360,24 @@ func TestNetworkNotifyAddPeerAndRemovePeer(t *testing.T) {
return nil return nil
}, metrics.NoopMetrics, &NoopApplicationScorer{}) }, metrics.NoopMetrics, &NoopApplicationScorer{})
waitChan := make(chan struct{}, 1) waitChan := make(chan struct{}, 2)
var connectedOnce sync.Once
var disconnectedOnce sync.Once
hostA.Network().Notify(&network.NotifyBundle{ hostA.Network().Notify(&network.NotifyBundle{
ConnectedF: func(nw network.Network, conn network.Conn) { ConnectedF: func(nw network.Network, conn network.Conn) {
connectedOnce.Do(func() {
syncCl.AddPeer(conn.RemotePeer()) syncCl.AddPeer(conn.RemotePeer())
waitChan <- struct{}{} waitChan <- struct{}{}
})
}, },
DisconnectedF: func(nw network.Network, conn network.Conn) { DisconnectedF: func(nw network.Network, conn network.Conn) {
disconnectedOnce.Do(func() {
// only when no connection is available, we can remove the peer // only when no connection is available, we can remove the peer
if nw.Connectedness(conn.RemotePeer()) == network.NotConnected { if nw.Connectedness(conn.RemotePeer()) == network.NotConnected {
syncCl.RemovePeer(conn.RemotePeer()) syncCl.RemovePeer(conn.RemotePeer())
} }
waitChan <- struct{}{} waitChan <- struct{}{}
})
}, },
}) })
syncCl.Start() syncCl.Start()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment