Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Undo implementing ping again
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Nov 16, 2022
1 parent b697f1e commit e67b51f
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions test/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((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)
}
Expand Down

0 comments on commit e67b51f

Please sign in to comment.