@@ -867,7 +867,8 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
867
867
await Promise . all ( sendRecv )
868
868
await tearDownGossipsubs ( psubs )
869
869
} )
870
- it ( 'test gossipsub direct peers' , async function ( ) {
870
+
871
+ it . only ( 'test gossipsub direct peers' , async function ( ) {
871
872
// Create 3 gossipsub nodes
872
873
// 2 and 3 with direct peer connections with each other
873
874
// Connect nodes: 2 <- 1 -> 3
@@ -914,9 +915,11 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
914
915
expect ( libp2ps [ 1 ] . connectionManager . get ( libp2ps [ 2 ] . peerId ) ) . to . be . ok
915
916
916
917
const topic = 'foobar'
917
- psubs . forEach ( ( ps ) => ps . subscribe ( topic ) )
918
-
919
- await Promise . all ( psubs . map ( ( ps ) => awaitEvents ( ps , 'gossipsub:heartbeat' , 1 ) ) )
918
+ const peerIdStrs = libp2ps . map ( ( libp2p ) => libp2p . peerId . toB58String ( ) )
919
+ const subscriptionPromises = psubs . map ( ( psub ) => checkReceivedSubscriptions ( psub , peerIdStrs , topic ) )
920
+ psubs . forEach ( ps => ps . subscribe ( topic ) )
921
+ await Promise . all ( psubs . map ( ps => awaitEvents ( ps , 'gossipsub:heartbeat' , 1 ) ) )
922
+ await subscriptionPromises
920
923
921
924
let sendRecv = [ ]
922
925
for ( let i = 0 ; i < 3 ; i ++ ) {
@@ -930,11 +933,18 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
930
933
}
931
934
await Promise . all ( sendRecv )
932
935
936
+ const connectPromises = [ 1 , 2 ] . map ( ( i ) => new Promise < void > ( ( resolve , reject ) => {
937
+ const t = setTimeout ( reject , 3000 )
938
+ libp2ps [ i ] . connectionManager . once ( 'peer:connect' , ( ) => {
939
+ clearTimeout ( t )
940
+ resolve ( )
941
+ } )
942
+ } ) )
933
943
// disconnect the direct peers to test reconnection
934
- libp2ps [ 1 ] . connectionManager . getAll ( libp2ps [ 2 ] . peerId ) . forEach ( ( c ) => c . close ( ) )
944
+ await libp2ps [ 1 ] . hangUp ( libp2ps [ 2 ] . peerId ) ;
935
945
936
946
await Promise . all ( psubs . map ( ( ps ) => awaitEvents ( ps , 'gossipsub:heartbeat' , 5 ) ) )
937
-
947
+ await Promise . all ( connectPromises )
938
948
expect ( libp2ps [ 1 ] . connectionManager . get ( libp2ps [ 2 ] . peerId ) ) . to . be . ok
939
949
940
950
sendRecv = [ ]
0 commit comments