Skip to content

Commit

Permalink
chore: remove setTimeout from test
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 10, 2024
1 parent 6d72709 commit 6453a80
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions .release-please.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"packages/peer-id": {},
"packages/peer-record": {},
"packages/peer-store": {},
"packages/pnet": {},
"packages/protocol-autonat": {},
"packages/protocol-dcutr": {},
"packages/protocol-echo": {},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
"release:rc": "aegir release-rc",
"docs": "aegir docs",
"docs:no-publish": "aegir docs --publish false -- --exclude interop --exclude doc",
"postinstall": "patch-package"
"postinstall": "patch-package && rm -rf node_modules/@chainsafe/libp2p-yamux/node_modules node_modules/@chainsafe/libp2p-noise/node_modules node_modules/@chainsafe/libp2p-gossipsub/node_modules node_modules/@libp2p/daemon-client/node_modules node_modules/@libp2p/daemon-server/node_modules node_modules/@libp2p/daemon-protocol/node_modules node_modules/@libp2p/interop/node_modules"
},
"devDependencies": {
"aegir": "^44.0.1",
"npm-run-all": "^4.1.5",
"patch-package": "^8.0.0"
"patch-package": "^8.0.0",
"rimraf": "^6.0.1"
},
"eslintConfig": {
"extends": "ipfs",
Expand Down
17 changes: 13 additions & 4 deletions packages/kad-dht/test/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ describe('QueryManager', () => {
})
await manager.start()

const deferred = pDefer()
const controller = new AbortController()
let aborted

Expand All @@ -331,16 +332,24 @@ describe('QueryManager', () => {
aborted = true
})

deferred.resolve()

await delay(1000)

yield topology[peer.toString()].event
}

setTimeout(() => {
controller.abort()
}, 10)
// start the query
const queryPromise = all(manager.run(key, queryFunc, { signal: controller.signal }))

// wait for the query function to be invoked
await deferred.promise

// abort the query
controller.abort()

await expect(all(manager.run(key, queryFunc, { signal: controller.signal }))).to.eventually.be.rejected()
// the should have been aborted
await expect(queryPromise).to.eventually.be.rejected()
.with.property('name', 'QueryAbortedError')

expect(aborted).to.be.true()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa

onProgress?.(new CustomProgressEvent('webrtc:read-sdp-answer'))

log.trace('initiator read SDP answer')

// read answer
const answerMessage = await messageStream.read({
signal
Expand All @@ -147,7 +149,7 @@ export async function initiateConnection ({ rtcConfiguration, dataChannel, signa
throw new SDPHandshakeFailedError('Remote should send an SDP answer')
}

log.trace('initiator receive SDP answer %s', answerMessage.data)
log.trace('initiator received SDP answer %s', answerMessage.data)

const answerSdp = new RTCSessionDescription({ type: 'answer', sdp: answerMessage.data })
await peerConnection.setRemoteDescription(answerSdp).catch(err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
})
}

log.trace('recipient read SDP offer')

// read an SDP offer
const pbOffer = await messageStream.read({
signal
Expand All @@ -49,7 +51,7 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
throw new SDPHandshakeFailedError(`expected message type SDP_OFFER, received: ${pbOffer.type ?? 'undefined'} `)
}

log.trace('recipient receive SDP offer %s', pbOffer.data)
log.trace('recipient received SDP offer %s', pbOffer.data)

const offer = new RTCSessionDescription({
type: 'offer',
Expand Down

0 comments on commit 6453a80

Please sign in to comment.