Skip to content

Commit

Permalink
Make test more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Sep 27, 2024
1 parent 70cebe1 commit eb1e8d4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,15 @@ test('peer-discovery object deleted when corresponding connection closes (server
connected.pass('swarm2')
conn.on('error', noop)
})

let resolveConnClosed = null
const connClosed = new Promise(resolve => {
resolveConnClosed = resolve
})
swarm1.on('connection', (conn) => {
otherConnected.pass('swarm1')
conn.on('error', noop)
conn.on('close', resolveConnClosed)
})

const topic = Buffer.alloc(32).fill('hello world')
Expand All @@ -634,7 +640,7 @@ test('peer-discovery object deleted when corresponding connection closes (server
await swarm2.destroy()

// Ensure other side detects closed connection
await eventFlush()
await connClosed

t.is(swarm1.peers.size, 0, 'No peerInfo memory leak')

Expand Down Expand Up @@ -791,7 +797,3 @@ test('topic and peer get unslabbed in PeerInfo', async (t) => {
})

function noop () {}

function eventFlush () {
return new Promise(resolve => setImmediate(resolve))
}

0 comments on commit eb1e8d4

Please sign in to comment.