Skip to content

Commit

Permalink
tests: fix tests after 436
Browse files Browse the repository at this point in the history
This wasn't caught because the tests hadn't run due to the test.Flaky.
  • Loading branch information
Jorropo committed Aug 17, 2023
1 parent 1d2f5e5 commit 0e9dc33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The following emojis are used to highlight certain changes:

### Fixed

- Address a Bitswap findpeers / connect race condition that can prevent peer communication ([#435](https://github.com/ipfs/boxo/issues/435))

### Security

## [v0.11.0]
Expand Down Expand Up @@ -72,7 +74,6 @@ The following emojis are used to highlight certain changes:

- Removed mentions of unused ARC algorithm ([#336](https://github.com/ipfs/boxo/issues/366#issuecomment-1597253540))
- Handle `_redirects` file when `If-None-Match` header is present ([#412](https://github.com/ipfs/boxo/pull/412))
- Address a Bitswap findpeers / connect race condition that can prevent peer communication ([#435](https://github.com/ipfs/boxo/issues/435))

### Security

Expand Down
32 changes: 16 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 @@ -72,27 +69,32 @@ func TestConnectEventManagerConnectDisconnect(t *testing.T) {
wait(t, cem)
require.Equal(t, expectedEvents, connListener.events)

// Block up the event loop.
// Blocking up the event loop eventually resolves once free.
var asyncEvents sync.WaitGroup
asyncEvents.Add(1)
connListener.Lock()
cem.Connected(peers[1])
expectedEvents = append(expectedEvents, mockConnEvent{
peer: peers[1],
connected: true,
})
go func() {
defer asyncEvents.Done()

// We don't expect this to show up.
cem.Disconnected(peers[0])
cem.Connected(peers[0])
cem.Connected(peers[1])
expectedEvents = append(expectedEvents, mockConnEvent{
peer: peers[1],
connected: true,
})

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

connListener.Unlock()
asyncEvents.Wait()

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 +144,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 0e9dc33

Please sign in to comment.