File tree Expand file tree Collapse file tree 5 files changed +50
-14
lines changed
Expand file tree Collapse file tree 5 files changed +50
-14
lines changed Original file line number Diff line number Diff line change 1212 runs-on : ubuntu-latest
1313 steps :
1414 - uses : actions/checkout@v2
15+ - uses : actions/setup-node@v2
16+ with :
17+ node-version : lts/*
1518 - run : npm install
1619 - run : npm run lint
1720 - run : npm run prebuild
@@ -22,11 +25,11 @@ jobs:
2225 strategy :
2326 matrix :
2427 os : [windows-latest, ubuntu-latest, macos-latest]
25- node : [14 ]
28+ node : [16 ]
2629 fail-fast : false
2730 steps :
2831 - uses : actions/checkout@v2
29- - uses : actions/setup-node@v1
32+ - uses : actions/setup-node@v2
3033 with :
3134 node-version : ${{ matrix.node }}
3235 - run : npm install
3841 runs-on : ubuntu-latest
3942 steps :
4043 - uses : actions/checkout@v2
44+ - uses : actions/setup-node@v2
45+ with :
46+ node-version : lts/*
4147 - run : npm install
4248 - run : npm run prebuild
4349 - run : npx aegir test -t browser -t webworker --bail
4652 runs-on : ubuntu-latest
4753 steps :
4854 - uses : actions/checkout@v2
55+ - uses : actions/setup-node@v2
56+ with :
57+ node-version : lts/*
4958 - run : npm install
5059 - run : npm run prebuild
5160 - run : npx aegir test -t browser -t webworker --bail -- --browser firefox
Original file line number Diff line number Diff line change 4444 "denque" : " ^1.5.0" ,
4545 "err-code" : " ^3.0.1" ,
4646 "it-pipe" : " ^1.1.0" ,
47- "libp2p-interfaces" : " ^1.1.0 " ,
48- "peer-id" : " ^0.15.3 " ,
47+ "libp2p-interfaces" : " ^2.0.1 " ,
48+ "peer-id" : " ^0.16.0 " ,
4949 "protobufjs" : " ^6.11.2" ,
5050 "time-cache" : " ^0.3.0" ,
5151 "uint8arrays" : " ^3.0.0"
5656 "@types/mocha" : " ^8.2.2" ,
5757 "@typescript-eslint/eslint-plugin" : " ^3.0.2" ,
5858 "@typescript-eslint/parser" : " ^3.0.2" ,
59- "aegir" : " ^35 .0.1 " ,
59+ "aegir" : " ^36 .0.2 " ,
6060 "benchmark" : " ^2.1.4" ,
6161 "buffer" : " ^6.0.3" ,
6262 "chai" : " ^4.2.0" ,
7171 "eslint-plugin-promise" : " ^4.2.1" ,
7272 "eslint-plugin-standard" : " ^4.0.1" ,
7373 "it-pair" : " ^1.0.0" ,
74- "libp2p" : " ^0.32 .0" ,
75- "libp2p-floodsub" : " ^0.27 .0" ,
76- "libp2p-interfaces-compliance-tests" : " ^1 .0.1 " ,
74+ "libp2p" : " ^0.35 .0" ,
75+ "libp2p-floodsub" : " ^0.28 .0" ,
76+ "libp2p-interfaces-compliance-tests" : " ^2 .0.3 " ,
7777 "libp2p-mplex" : " ^0.10.3" ,
7878 "libp2p-websockets" : " ^0.16.1" ,
7979 "lodash" : " ^4.17.15" ,
Original file line number Diff line number Diff line change @@ -212,9 +212,14 @@ describe('2 nodes', () => {
212212 } )
213213
214214 it ( 'Publish to a topic after unsubscribe' , async ( ) => {
215+ const promises = [
216+ new Promise ( ( resolve ) => nodes [ 1 ] . once ( 'pubsub:subscription-change' , resolve ) ) ,
217+ new Promise ( ( resolve ) => nodes [ 1 ] . once ( 'gossipsub:heartbeat' , resolve ) )
218+ ]
219+
215220 nodes [ 0 ] . unsubscribe ( topic )
216- await new Promise ( ( resolve ) => nodes [ 1 ] . once ( 'pubsub:subscription-change' , resolve ) )
217- await new Promise ( ( resolve ) => nodes [ 1 ] . once ( 'gossipsub:heartbeat' , resolve ) )
221+
222+ await Promise . all ( promises )
218223
219224 const promise = new Promise ( ( resolve , reject ) => {
220225 nodes [ 0 ] . once ( topic , reject )
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ const {
1111 first,
1212 createGossipsubs,
1313 connectGossipsubs,
14- stopNode
14+ stopNode,
15+ waitForAllNodesToBePeered
1516} = require ( './utils' )
1617
1718describe ( 'gossip' , ( ) => {
@@ -31,9 +32,9 @@ describe('gossip', () => {
3132 // add subscriptions to each node
3233 nodes . forEach ( ( n ) => n . subscribe ( topic ) )
3334
35+ // every node connected to every other
3436 await connectGossipsubs ( nodes )
35- // await subscription propagation
36- await delay ( 50 )
37+ await waitForAllNodesToBePeered ( nodes )
3738
3839 // await mesh rebalancing
3940 await Promise . all ( nodes . map ( ( n ) => new Promise ( ( resolve ) => n . once ( 'gossipsub:heartbeat' , resolve ) ) ) )
@@ -67,7 +68,8 @@ describe('gossip', () => {
6768
6869 // every node connected to every other
6970 await connectGossipsubs ( nodes )
70- await delay ( 500 )
71+ await waitForAllNodesToBePeered ( nodes )
72+
7173 // await mesh rebalancing
7274 await Promise . all ( nodes . map ( ( n ) => new Promise ( ( resolve ) => n . once ( 'gossipsub:heartbeat' , resolve ) ) ) )
7375 await delay ( 500 )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const { expect } = require('chai')
44
55const FloodSub = require ( 'libp2p-floodsub' )
66const PeerId = require ( 'peer-id' )
7+ const delay = require ( 'delay' )
78
89exports . first = ( map ) => map . values ( ) . next ( ) . value
910
@@ -52,3 +53,22 @@ exports.getMsgId = (msg) => {
5253 result . set ( seqno , from . length )
5354 return result
5455}
56+
57+ exports . waitForAllNodesToBePeered = async ( peers , attempts = 10 , delayMs = 100 ) => {
58+ const nodeIds = peers . map ( peer => peer . peerId . toB58String ( ) )
59+
60+ for ( let i = 0 ; i < attempts ; i ++ ) {
61+ for ( const node of peers ) {
62+ const nodeId = node . peerId . toB58String ( )
63+ const others = nodeIds . filter ( peerId => peerId !== nodeId )
64+
65+ const missing = others . some ( other => ! node . peers . has ( other ) )
66+
67+ if ( ! missing ) {
68+ return
69+ }
70+ }
71+
72+ await delay ( delayMs )
73+ }
74+ }
You can’t perform that action at this time.
0 commit comments