This repository was archived by the owner on May 7, 2024. It is now read-only.
File tree 1 file changed +1
-33
lines changed
1 file changed +1
-33
lines changed Original file line number Diff line number Diff line change @@ -27,39 +27,7 @@ describe('libp2p-webtransport', () => {
27
27
28
28
// Ping many times
29
29
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 )
63
31
64
32
expect ( res ) . to . be . greaterThan ( - 1 )
65
33
}
You can’t perform that action at this time.
0 commit comments