Skip to content

Commit

Permalink
chore: investigate interop test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko committed Jan 15, 2024
1 parent 7f7943f commit e958d1b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/lib/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ class Filter extends BaseProtocol implements IReceiver {
})
)[0];

if (!peer) {
throw new Error("No peer found to initiate subscription.");
}

const subscription =
this.getActiveSubscription(pubsubTopic, peer.id.toString()) ??
this.setActiveSubscription(
Expand Down
22 changes: 16 additions & 6 deletions packages/tests/tests/filter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,22 @@ export async function runNodes(
log.error("jswaku node failed to start:", error);
}

if (waku) {
await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
await nwaku.ensureSubscriptions(pubsubTopics);
return [nwaku, waku];
} else {
if (!waku) {
throw new Error("Failed to initialize waku");
}

await waku.dial(await nwaku.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
await nwaku.ensureSubscriptions(pubsubTopics);

const wakuPeers = await waku.libp2p.peerStore.all();
const nwakuPeers = await nwaku.peers();

if (wakuPeers.length < 1 || nwakuPeers.length < 1) {
throw new Error(
`Expected at least 1 peer in each node. Got waku: ${wakuPeers.length} and nwaku: ${nwakuPeers.length}`
);
}

return [nwaku, waku];
}
22 changes: 6 additions & 16 deletions packages/tests/tests/store/multiple_pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);

waku = await startAndConnectLightNode(nwaku, [
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);
});

afterEach(async function () {
Expand All @@ -363,10 +368,7 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customContentTopic1,
customShardedPubsubTopic1
);
waku = await startAndConnectLightNode(nwaku, [
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);

const messages = await processQueriedMessages(
waku,
[customDecoder1],
Expand Down Expand Up @@ -397,11 +399,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic2
);

waku = await startAndConnectLightNode(nwaku, [
customShardedPubsubTopic1,
customShardedPubsubTopic2
]);

const customMessages = await processQueriedMessages(
waku,
[customDecoder1],
Expand Down Expand Up @@ -451,13 +448,6 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic2
);

waku = await createLightNode({
staticNoiseKey: NOISE_KEY_1,
pubsubTopics: [customShardedPubsubTopic1, customShardedPubsubTopic2]
});
await waku.start();

await waku.dial(await nwaku.getMultiaddrWithId());
await waku.dial(await nwaku2.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Store]);

Expand Down
10 changes: 10 additions & 0 deletions packages/tests/tests/store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ export async function startAndConnectLightNode(
await waku.start();
await waku.dial(await instance.getMultiaddrWithId());
await waitForRemotePeer(waku, [Protocols.Store]);

const wakuPeers = await waku.libp2p.peerStore.all();
const nwakuPeers = await instance.peers();

if (wakuPeers.length < 1 || nwakuPeers.length < 1) {
throw new Error(
`Expected at least 1 peer in each node. Got waku: ${wakuPeers.length} and nwaku: ${nwakuPeers.length}`
);
}

log.info("Waku node created");
return waku;
}
Expand Down

0 comments on commit e958d1b

Please sign in to comment.