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 2bbaf43
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"packages/connection-encrypter-plaintext":"1.1.6","packages/connection-encrypter-tls":"1.1.5","packages/crypto":"4.1.9","packages/interface":"1.7.0","packages/interface-compliance-tests":"5.4.12","packages/interface-internal":"1.3.4","packages/kad-dht":"12.1.5","packages/keychain":"4.1.6","packages/libp2p":"1.9.4","packages/logger":"4.0.20","packages/metrics-devtools":"0.2.5","packages/metrics-prometheus":"3.1.5","packages/metrics-simple":"1.1.5","packages/multistream-select":"5.1.17","packages/peer-collections":"5.2.9","packages/peer-discovery-bootstrap":"10.1.5","packages/peer-discovery-mdns":"10.1.5","packages/peer-id":"4.2.4","packages/peer-record":"7.0.25","packages/peer-store":"10.1.5","packages/protocol-autonat":"1.1.5","packages/protocol-dcutr":"1.1.5","packages/protocol-echo":"1.1.5","packages/protocol-fetch":"1.1.5","packages/protocol-identify":"2.1.5","packages/protocol-perf":"3.1.5","packages/protocol-ping":"1.1.6","packages/pubsub":"9.0.26","packages/pubsub-floodsub":"9.1.5","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"10.1.5","packages/transport-circuit-relay-v2":"1.1.5","packages/transport-tcp":"9.1.6","packages/transport-webrtc":"4.1.10","packages/transport-websockets":"8.2.0","packages/transport-webtransport":"4.1.9","packages/upnp-nat":"1.2.5","packages/utils":"5.4.9"}
{"packages/connection-encrypter-plaintext":"2.0.0","packages/connection-encrypter-tls":"2.0.0","packages/crypto":"5.0.0","packages/interface":"2.0.0","packages/interface-compliance-tests":"6.0.0","packages/interface-internal":"2.0.0","packages/kad-dht":"13.0.0","packages/keychain":"5.0.0","packages/libp2p":"2.0.0","packages/logger":"5.0.0","packages/metrics-devtools":"1.0.0","packages/metrics-prometheus":"4.0.0","packages/metrics-simple":"1.1.6","packages/multistream-select":"6.0.0","packages/peer-collections":"6.0.0","packages/peer-discovery-bootstrap":"11.0.0","packages/peer-discovery-mdns":"11.0.0","packages/peer-id":"5.0.0","packages/peer-record":"8.0.0","packages/peer-store":"11.0.0","packages/pnet":"2.0.0","packages/protocol-autonat":"2.0.0","packages/protocol-dcutr":"2.0.0","packages/protocol-echo":"2.0.0","packages/protocol-fetch":"2.0.0","packages/protocol-identify":"3.0.0","packages/protocol-perf":"4.0.0","packages/protocol-ping":"2.0.0","packages/pubsub":"10.0.0","packages/pubsub-floodsub":"10.0.0","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"11.0.0","packages/transport-circuit-relay-v2":"2.0.0","packages/transport-tcp":"10.0.0","packages/transport-webrtc":"5.0.0","packages/transport-websockets":"9.0.0","packages/transport-webtransport":"5.0.0","packages/upnp-nat":"2.0.0","packages/utils":"6.0.0"}
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 2bbaf43

Please sign in to comment.