Skip to content

Commit

Permalink
fix(connecteventmanager): clean up tests for new synchronous flow
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg authored and Jorropo committed Aug 17, 2023
1 parent 59a2bca commit 7ec68c5
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions bitswap/network/connecteventmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/ipfs/boxo/bitswap/internal/testutil"
"github.com/ipfs/boxo/internal/test"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -50,8 +49,6 @@ func wait(t *testing.T, c *connectEventManager) {
}

func TestConnectEventManagerConnectDisconnect(t *testing.T) {
test.Flaky(t)

connListener := newMockConnListener()
peers := testutil.GeneratePeers(2)
cem := newConnectEventManager(connListener)
Expand All @@ -68,31 +65,26 @@ func TestConnectEventManagerConnectDisconnect(t *testing.T) {
connected: true,
})

// Flush the event queue.
wait(t, cem)
require.Equal(t, expectedEvents, connListener.events)

// Block up the event loop.
connListener.Lock()
cem.Connected(peers[1])
expectedEvents = append(expectedEvents, mockConnEvent{
peer: peers[1],
connected: true,
})
require.Equal(t, expectedEvents, connListener.events)

// We don't expect this to show up.
cem.Disconnected(peers[0])
cem.Connected(peers[0])

connListener.Unlock()

expectedEvents = append(expectedEvents, mockConnEvent{
peer: peers[0],
connected: false,
})
// Flush the event queue.
wait(t, cem)
require.Equal(t, expectedEvents, connListener.events)
}

func TestConnectEventManagerMarkUnresponsive(t *testing.T) {
test.Flaky(t)

connListener := newMockConnListener()
p := testutil.GeneratePeers(1)[0]
cem := newConnectEventManager(connListener)
Expand Down Expand Up @@ -142,8 +134,6 @@ func TestConnectEventManagerMarkUnresponsive(t *testing.T) {
}

func TestConnectEventManagerDisconnectAfterMarkUnresponsive(t *testing.T) {
test.Flaky(t)

connListener := newMockConnListener()
p := testutil.GeneratePeers(1)[0]
cem := newConnectEventManager(connListener)
Expand Down

0 comments on commit 7ec68c5

Please sign in to comment.