From e67b51f4b3bd33f876cb3f987b6498138b532cc4 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 15 Nov 2022 19:18:07 -0800 Subject: [PATCH] Undo implementing ping again --- test/browser.ts | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/test/browser.ts b/test/browser.ts index a308eff..7cf5901 100644 --- a/test/browser.ts +++ b/test/browser.ts @@ -27,39 +27,7 @@ describe('libp2p-webtransport', () => { // Ping many times for (let index = 0; index < 100; index++) { - const now = Date.now() - - // Note we're re-implementing the ping protocol here because as of this - // writing, the standard js-libp2p ping implementation has some - // race-conditions when interacting with go-libp2p. We can work around it - // by waiting until we get a pong before closing the write stream. - const stream = await node.dialProtocol(ma, '/ipfs/ping/1.0.0') - - const data = new Uint8Array(32) - globalThis.crypto.getRandomValues(data) - - const pong = new Promise((resolve, reject) => { - (async () => { - for await (const chunk of stream.source) { - const v = chunk.subarray() - if (v.every((byte: number, i: number) => byte === data[i])) { - resolve() - } else { - reject(new Error('Wrong pong')) - } - } - })().catch(reject) - }) - - let res = -1 - await stream.sink((async function * () { - yield data - // Wait for the pong before we close the write side - await pong - res = Date.now() - now - })()) - - await stream.close() + const res = await node.ping(ma) expect(res).to.be.greaterThan(-1) }