diff --git a/CHANGELOG.md b/CHANGELOG.md index f3a849a..8647bb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [7.0.1](https://github.com/libp2p/interop/compare/v7.0.0...v7.0.1) (2023-02-28) + + +### Bug Fixes + +* wait for gossipsub heartbeat before sending message ([#94](https://github.com/libp2p/interop/issues/94)) ([dffdff0](https://github.com/libp2p/interop/commit/dffdff06e84427f4205d2a70cdad1e1be2fc3cd3)) + ## [7.0.0](https://github.com/libp2p/interop/compare/v6.0.3...v7.0.0) (2023-02-24) diff --git a/package.json b/package.json index a8e89ec..de025b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@libp2p/interop", - "version": "7.0.0", + "version": "7.0.1", "description": "Interoperability Tests for libp2p", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/libp2p/interop#readme", @@ -137,6 +137,7 @@ "@libp2p/interface-peer-id": "^2.0.1", "@libp2p/interface-peer-info": "^1.0.7", "@multiformats/multiaddr": "^11.4.0", + "delay": "^5.0.0", "it-all": "^2.0.0", "it-first": "^2.0.0", "it-handshake": "^4.1.2", diff --git a/src/pubsub/floodsub.ts b/src/pubsub/floodsub.ts index e33d500..55c2678 100644 --- a/src/pubsub/floodsub.ts +++ b/src/pubsub/floodsub.ts @@ -4,7 +4,7 @@ import { expect } from 'aegir/chai' import type { Daemon, DaemonFactory, NodeType, SpawnOptions } from '../index.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import first from 'it-first' -import { waitForBothSubscribed } from './utils.js' +import { waitForSubscribed } from './utils.js' export function floodsubTests (factory: DaemonFactory): void { const nodeTypes: NodeType[] = ['js', 'go'] @@ -61,7 +61,7 @@ function runFloodsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optio } const publisher = async (): Promise => { - await waitForBothSubscribed(topic, peerA, peerB) + await waitForSubscribed(topic, peerA, peerB) await peerA.client.pubsub.publish(topic, data) } diff --git a/src/pubsub/gossipsub.ts b/src/pubsub/gossipsub.ts index 9efcd8a..a2042ba 100644 --- a/src/pubsub/gossipsub.ts +++ b/src/pubsub/gossipsub.ts @@ -4,7 +4,7 @@ import { expect } from 'aegir/chai' import type { Daemon, DaemonFactory, NodeType, SpawnOptions } from '../index.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import first from 'it-first' -import { waitForBothSubscribed } from './utils.js' +import { waitForSubscribed } from './utils.js' export function gossipsubTests (factory: DaemonFactory): void { const nodeTypes: NodeType[] = ['js', 'go'] @@ -61,7 +61,7 @@ function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, opti } const publisher = async (): Promise => { - await waitForBothSubscribed(topic, peerA, peerB) + await waitForSubscribed(topic, peerA, peerB) await peerA.client.pubsub.publish(topic, data) } diff --git a/src/pubsub/hybrid.ts b/src/pubsub/hybrid.ts index f12c80a..a5afae1 100644 --- a/src/pubsub/hybrid.ts +++ b/src/pubsub/hybrid.ts @@ -4,7 +4,7 @@ import { expect } from 'aegir/chai' import type { Daemon, DaemonFactory, NodeType, SpawnOptions } from '../index.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import first from 'it-first' -import { waitForBothSubscribed } from './utils.js' +import { waitForSubscribed } from './utils.js' export function hybridTests (factory: DaemonFactory): void { const nodeTypes: NodeType[] = ['js', 'go'] @@ -61,7 +61,7 @@ function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, options } const publisher = async (): Promise => { - await waitForBothSubscribed(topic, peerA, peerB) + await waitForSubscribed(topic, peerA, peerB) await peerA.client.pubsub.publish(topic, data) } diff --git a/src/pubsub/utils.ts b/src/pubsub/utils.ts index 78447ca..4cc123d 100644 --- a/src/pubsub/utils.ts +++ b/src/pubsub/utils.ts @@ -1,26 +1,22 @@ import pWaitFor from 'p-wait-for' -import type { Daemon } from '..' +import delay from 'delay' +import type { Daemon } from '../index.js' -export async function waitForBothSubscribed (topic: string, a: Daemon, b: Daemon): Promise { - await a.client.pubsub.subscribe(topic) - await b.client.pubsub.subscribe(topic) - - const idA = await a.client.identify() +/** + * Wait for daemon a to see daemon b in it's subscriber list + * for the passed topic + */ +export async function waitForSubscribed (topic: string, a: Daemon, b: Daemon): Promise { const idB = await b.client.identify() // wait for subscription stream - await Promise.all([ - await pWaitFor(async () => { - const peers = await a.client.pubsub.getSubscribers(topic) - return peers.map(p => p.toString()).includes(idB.peerId.toString()) - }, { - interval: 500 - }), - await pWaitFor(async () => { - const peers = await b.client.pubsub.getSubscribers(topic) - return peers.map(p => p.toString()).includes(idA.peerId.toString()) - }, { - interval: 500 - }) - ]) + await pWaitFor(async () => { + const peers = await a.client.pubsub.getSubscribers(topic) + return peers.map(p => p.toString()).includes(idB.peerId.toString()) + }, { + interval: 500 + }) + + // wait for the gossipsub heartbeat to rebalance the mesh + await delay(2000) }