From 3e7b95e604e87fd34b1f9540ee4677a3e1b33e6e Mon Sep 17 00:00:00 2001 From: Florin Barbu Date: Mon, 22 Jan 2024 10:38:59 +0200 Subject: [PATCH] chore: split 100 topics tests in old and new behaviour (#1803) * chore: split 100 topics tests in old and new behavioud * add remove test TODO --- .../filter/single_node/subscribe.node.spec.ts | 83 ++++++++++++++++++- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/packages/tests/tests/filter/single_node/subscribe.node.spec.ts b/packages/tests/tests/filter/single_node/subscribe.node.spec.ts index ae9de562c4..e0ca48498d 100644 --- a/packages/tests/tests/filter/single_node/subscribe.node.spec.ts +++ b/packages/tests/tests/filter/single_node/subscribe.node.spec.ts @@ -220,11 +220,14 @@ describe("Waku Filter V2: Subscribe", function () { }); }); - it("Subscribe to 100 topics at once and receives messages", async function () { - let topicCount = 30; + it("Subscribe to 100 topics (new limit) at once and receives messages", async function () { + let topicCount: number; if (isNwakuAtLeast("0.24.0")) { this.timeout(50000); topicCount = 100; + } else { + // skipping for old versions where the limit is 30 + this.skip(); } const td = generateTestData(topicCount); @@ -255,10 +258,82 @@ describe("Waku Filter V2: Subscribe", function () { } }); - it("Error when try to subscribe to more than 101 topics", async function () { - let topicCount = 31; + //TODO: remove test when WAKUNODE_IMAGE is 0.24.0 + it("Subscribe to 30 topics (old limit) at once and receives messages", async function () { + let topicCount: number; + if (isNwakuAtLeast("0.24.0")) { + // skipping for new versions where the new limit is 100 + this.skip(); + } else { + topicCount = 30; + } + + const td = generateTestData(topicCount); + + await subscription.subscribe(td.decoders, messageCollector.callback); + + // Send a unique message on each topic. + for (let i = 0; i < topicCount; i++) { + await waku.lightPush.send(td.encoders[i], { + payload: utf8ToBytes(`Message for Topic ${i + 1}`) + }); + } + + // Open issue here: https://github.com/waku-org/js-waku/issues/1790 + // That's why we use the try catch block + try { + // Verify that each message was received on the corresponding topic. + expect(await messageCollector.waitForMessages(topicCount)).to.eq(true); + td.contentTopics.forEach((topic, index) => { + messageCollector.verifyReceivedMessage(index, { + expectedContentTopic: topic, + expectedMessageText: `Message for Topic ${index + 1}` + }); + }); + } catch (error) { + console.warn( + "This test still fails because of https://github.com/waku-org/js-waku/issues/1790" + ); + } + }); + + it("Error when try to subscribe to more than 101 topics (new limit)", async function () { + let topicCount: number; if (isNwakuAtLeast("0.24.0")) { topicCount = 101; + } else { + // skipping for old versions where the limit is 30 + this.skip(); + } + const td = generateTestData(topicCount); + + try { + await subscription.subscribe(td.decoders, messageCollector.callback); + throw new Error( + `Subscribe to ${topicCount} topics was successful but was expected to fail with a specific error.` + ); + } catch (err) { + if ( + err instanceof Error && + err.message.includes( + `exceeds maximum content topics: ${topicCount - 1}` + ) + ) { + return; + } else { + throw err; + } + } + }); + + //TODO: remove test when WAKUNODE_IMAGE is 0.24.0 + it("Error when try to subscribe to more than 31 topics (old limit)", async function () { + let topicCount: number; + if (isNwakuAtLeast("0.24.0")) { + // skipping for new versions where the new limit is 100 + this.skip(); + } else { + topicCount = 31; } const td = generateTestData(topicCount);