From 6453a806d4bfed4e56d3c9980c6f86cf90152ac1 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 10 Sep 2024 09:44:16 +0100 Subject: [PATCH] chore: remove setTimeout from test --- .release-please.json | 1 + package.json | 5 +++-- packages/kad-dht/test/query.spec.ts | 17 +++++++++++++---- .../private-to-private/initiate-connection.ts | 4 +++- .../signaling-stream-handler.ts | 4 +++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.release-please.json b/.release-please.json index 5f427cd535..07baf97322 100644 --- a/.release-please.json +++ b/.release-please.json @@ -29,6 +29,7 @@ "packages/peer-id": {}, "packages/peer-record": {}, "packages/peer-store": {}, + "packages/pnet": {}, "packages/protocol-autonat": {}, "packages/protocol-dcutr": {}, "packages/protocol-echo": {}, diff --git a/package.json b/package.json index 6c546c3279..cc35e3dca2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/kad-dht/test/query.spec.ts b/packages/kad-dht/test/query.spec.ts index 44617e3f86..33fb5d6277 100644 --- a/packages/kad-dht/test/query.spec.ts +++ b/packages/kad-dht/test/query.spec.ts @@ -312,6 +312,7 @@ describe('QueryManager', () => { }) await manager.start() + const deferred = pDefer() const controller = new AbortController() let aborted @@ -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() diff --git a/packages/transport-webrtc/src/private-to-private/initiate-connection.ts b/packages/transport-webrtc/src/private-to-private/initiate-connection.ts index a4494c4a7e..f4299ace9e 100644 --- a/packages/transport-webrtc/src/private-to-private/initiate-connection.ts +++ b/packages/transport-webrtc/src/private-to-private/initiate-connection.ts @@ -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 @@ -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 => { diff --git a/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts b/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts index 067693dc5f..161d1af300 100644 --- a/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts +++ b/packages/transport-webrtc/src/private-to-private/signaling-stream-handler.ts @@ -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 @@ -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',