Skip to content

Commit a580b59

Browse files
committed
Fix 'test gossipsub direct peers'
1 parent 74d26cc commit a580b59

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

test/go-gossipsub.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
867867
await Promise.all(sendRecv)
868868
await tearDownGossipsubs(psubs)
869869
})
870-
it('test gossipsub direct peers', async function () {
870+
871+
it.only('test gossipsub direct peers', async function () {
871872
// Create 3 gossipsub nodes
872873
// 2 and 3 with direct peer connections with each other
873874
// Connect nodes: 2 <- 1 -> 3
@@ -914,9 +915,11 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
914915
expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok
915916

916917
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
920923

921924
let sendRecv = []
922925
for (let i = 0; i < 3; i++) {
@@ -930,11 +933,18 @@ describe('go-libp2p-pubsub gossipsub tests', function () {
930933
}
931934
await Promise.all(sendRecv)
932935

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+
}))
933943
// 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);
935945

936946
await Promise.all(psubs.map((ps) => awaitEvents(ps, 'gossipsub:heartbeat', 5)))
937-
947+
await Promise.all(connectPromises)
938948
expect(libp2ps[1].connectionManager.get(libp2ps[2].peerId)).to.be.ok
939949

940950
sendRecv = []

0 commit comments

Comments
 (0)