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

Commit e67b51f

Browse files
committed
Undo implementing ping again
1 parent b697f1e commit e67b51f

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

test/browser.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,7 @@ describe('libp2p-webtransport', () => {
2727

2828
// Ping many times
2929
for (let index = 0; index < 100; index++) {
30-
const now = Date.now()
31-
32-
// Note we're re-implementing the ping protocol here because as of this
33-
// writing, the standard js-libp2p ping implementation has some
34-
// race-conditions when interacting with go-libp2p. We can work around it
35-
// by waiting until we get a pong before closing the write stream.
36-
const stream = await node.dialProtocol(ma, '/ipfs/ping/1.0.0')
37-
38-
const data = new Uint8Array(32)
39-
globalThis.crypto.getRandomValues(data)
40-
41-
const pong = new Promise<void>((resolve, reject) => {
42-
(async () => {
43-
for await (const chunk of stream.source) {
44-
const v = chunk.subarray()
45-
if (v.every((byte: number, i: number) => byte === data[i])) {
46-
resolve()
47-
} else {
48-
reject(new Error('Wrong pong'))
49-
}
50-
}
51-
})().catch(reject)
52-
})
53-
54-
let res = -1
55-
await stream.sink((async function * () {
56-
yield data
57-
// Wait for the pong before we close the write side
58-
await pong
59-
res = Date.now() - now
60-
})())
61-
62-
await stream.close()
30+
const res = await node.ping(ma)
6331

6432
expect(res).to.be.greaterThan(-1)
6533
}

0 commit comments

Comments
 (0)