Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test more robust #183

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading