Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { Message, PubSub } from '@libp2p/interfaces/pubsub'
import type { PubSubArgs } from './index.js'
import type { Components } from '@libp2p/interfaces/components'
import { start, stop } from '../index.js'
import delay from 'delay'

export default (common: TestSetup<PubSub, PubSubArgs>) => {
describe('pubsub with multiple nodes', function () {
Expand Down Expand Up @@ -137,18 +138,21 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
psB.subscribe(topic)
psC.subscribe(topic)

let counter = 0

psA.addEventListener('message', incMsg)
psB.addEventListener('message', incMsg)
psC.addEventListener('message', incMsg)

await Promise.all([
waitForSubscriptionUpdate(psA, componentsB.getPeerId()),
waitForSubscriptionUpdate(psB, componentsA.getPeerId()),
waitForSubscriptionUpdate(psC, componentsB.getPeerId())
])

// GossipSub needs time to build the mesh overlay
await delay(1000)

let counter = 0

psA.addEventListener('message', incMsg)
psB.addEventListener('message', incMsg)
psC.addEventListener('message', incMsg)

const result = await psA.publish(topic, uint8ArrayFromString('hey'))

expect(result).to.have.property('recipients').with.property('length').greaterThanOrEqual(1)
Expand Down Expand Up @@ -190,10 +194,6 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
const defer = pDefer()
let counter = 0

psA.addEventListener('message', incMsg)
psB.addEventListener('message', incMsg)
psC.addEventListener('message', incMsg)

psA.subscribe(topic)
psB.subscribe(topic)
psC.subscribe(topic)
Expand All @@ -204,6 +204,13 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
waitForSubscriptionUpdate(psC, componentsB.getPeerId())
])

// GossipSub needs time to build the mesh overlay
await delay(1000)

psA.addEventListener('message', incMsg)
psB.addEventListener('message', incMsg)
psC.addEventListener('message', incMsg)

await psB.publish(topic, uint8ArrayFromString('hey'))

function incMsg (evt: CustomEvent<Message>) {
Expand Down Expand Up @@ -352,6 +359,9 @@ export default (common: TestSetup<PubSub, PubSubArgs>) => {
waitForSubscriptionUpdate(psE, componentsD.getPeerId())
])

// GossipSub needs time to build the mesh overlay
await delay(1000)

await psC.publish('Z', uint8ArrayFromString('hey from c'))

function incMsg (evt: CustomEvent<Message>) {
Expand Down