chore: use graceful timeout mechanism (#1841)

* use graceful timeout mechanism

* set max timeout for all hooks

* small fix

* small fix

* use MOCHA_HOOK_MAX_TIMEOUT as default timeoutDuration

* force retry even when the hook fails

* use custom hooks

* fix global timeout problem

* fix unwanted change

* fix enr issue

* force retry on before error as well
This commit is contained in:
Florin Barbu 2024-02-15 08:50:03 +02:00 committed by GitHub
parent a9fb796a7b
commit de5be4413b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
47 changed files with 350 additions and 284 deletions

View File

@ -61,3 +61,5 @@ export const TEST_TIMESTAMPS = [
1949153314000, 1949153314000,
undefined undefined
]; ];
export const MOCHA_HOOK_MAX_TIMEOUT = 50_000;

View File

@ -0,0 +1,68 @@
import { Logger } from "@waku/utils";
import { Suite } from "mocha";
import { MOCHA_HOOK_MAX_TIMEOUT } from "../constants";
const log = new Logger("test:mocha-hook");
function withGracefulTimeout(
asyncOperation: () => Promise<void>,
doneCallback: (error?: unknown) => void,
timeoutDuration: number = MOCHA_HOOK_MAX_TIMEOUT
): void {
let operationCompleted = false;
const wrapperOperation: () => Promise<void> = async () => {
try {
await asyncOperation();
if (!operationCompleted) {
operationCompleted = true;
log.info("Mocha hook completed successfully.");
doneCallback();
}
} catch (error) {
if (!operationCompleted) {
operationCompleted = true;
log.error(
"Mocha hook failed. Proceeding to the test so it can retry.",
error
);
doneCallback();
}
}
};
void wrapperOperation();
setTimeout(() => {
if (!operationCompleted) {
log.info(
"Custom timeout reached. Proceeding to the test so it can retry."
);
operationCompleted = true;
doneCallback();
}
}, timeoutDuration);
}
export const beforeEachCustom = function (
suite: Suite,
cb: () => Promise<void>
): void {
const timeoutBefore = suite.timeout();
suite.timeout(MOCHA_HOOK_MAX_TIMEOUT);
suite.beforeEach((done) => {
withGracefulTimeout(cb, done);
});
suite.timeout(timeoutBefore); // restore timeout to the original value
};
export const afterEachCustom = function (
suite: Suite,
cb: () => Promise<void>
): void {
const timeoutBefore = suite.timeout();
suite.timeout(MOCHA_HOOK_MAX_TIMEOUT);
suite.afterEach((done) => {
withGracefulTimeout(cb, done);
});
suite.timeout(timeoutBefore); // restore timeout to the original value
};

View File

@ -5,3 +5,4 @@ export * from "./wait_for_remote_peer_with_codec.js";
export * from "./delay.js"; export * from "./delay.js";
export * from "./base64_utf8.js"; export * from "./base64_utf8.js";
export * from "./waitForConnections.js"; export * from "./waitForConnections.js";
export * from "./custom_mocha_hooks.js";

View File

@ -4,7 +4,12 @@ import { createLightNode } from "@waku/sdk";
import { createRelayNode } from "@waku/sdk/relay"; import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai"; import { expect } from "chai";
import { delay, NOISE_KEY_1 } from "../../src/index.js"; import {
afterEachCustom,
beforeEachCustom,
delay,
NOISE_KEY_1
} from "../../src/index.js";
import { import {
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
@ -22,8 +27,7 @@ describe("Connection state", function () {
let nwaku1PeerId: Multiaddr; let nwaku1PeerId: Multiaddr;
let nwaku2PeerId: Multiaddr; let nwaku2PeerId: Multiaddr;
beforeEach(async () => { beforeEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
waku = await createLightNode({ shardInfo: { shards: [0] } }); waku = await createLightNode({ shardInfo: { shards: [0] } });
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
@ -33,8 +37,7 @@ describe("Connection state", function () {
nwaku2PeerId = await nwaku2.getMultiaddrWithId(); nwaku2PeerId = await nwaku2.getMultiaddrWithId();
}); });
afterEach(async () => { afterEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
await tearDownNodes([nwaku1, nwaku2], waku); await tearDownNodes([nwaku1, nwaku2], waku);
}); });

View File

@ -6,7 +6,7 @@ import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import sinon, { SinonSpy, SinonStub } from "sinon"; import sinon, { SinonSpy, SinonStub } from "sinon";
import { delay } from "../../src/index.js"; import { afterEachCustom, beforeEachCustom, delay } from "../../src/index.js";
import { tearDownNodes } from "../../src/index.js"; import { tearDownNodes } from "../../src/index.js";
const DELAY_MS = 1_000; const DELAY_MS = 1_000;
@ -20,8 +20,7 @@ describe("Dials", function () {
let isPeerTopicConfigured: SinonStub; let isPeerTopicConfigured: SinonStub;
let waku: LightNode; let waku: LightNode;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
waku = await createLightNode({ shardInfo: { shards: [0] } }); waku = await createLightNode({ shardInfo: { shards: [0] } });
isPeerTopicConfigured = sinon.stub( isPeerTopicConfigured = sinon.stub(
waku.connectionManager as any, waku.connectionManager as any,
@ -30,8 +29,7 @@ describe("Dials", function () {
isPeerTopicConfigured.resolves(true); isPeerTopicConfigured.resolves(true);
}); });
afterEach(async () => { afterEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
await tearDownNodes([], waku); await tearDownNodes([], waku);
isPeerTopicConfigured.restore(); isPeerTopicConfigured.restore();
sinon.restore(); sinon.restore();
@ -40,11 +38,11 @@ describe("Dials", function () {
describe("attemptDial method", function () { describe("attemptDial method", function () {
let attemptDialSpy: SinonSpy; let attemptDialSpy: SinonSpy;
beforeEach(function () { beforeEachCustom(this, async () => {
attemptDialSpy = sinon.spy(waku.connectionManager as any, "attemptDial"); attemptDialSpy = sinon.spy(waku.connectionManager as any, "attemptDial");
}); });
afterEach(function () { afterEachCustom(this, async () => {
attemptDialSpy.restore(); attemptDialSpy.restore();
}); });
@ -73,7 +71,7 @@ describe("Dials", function () {
describe("dialPeer method", function () { describe("dialPeer method", function () {
let peerStoreHasStub: SinonStub; let peerStoreHasStub: SinonStub;
let dialAttemptsForPeerHasStub: SinonStub; let dialAttemptsForPeerHasStub: SinonStub;
beforeEach(function () { beforeEachCustom(this, async () => {
getConnectionsStub = sinon.stub( getConnectionsStub = sinon.stub(
(waku.connectionManager as any).libp2p, (waku.connectionManager as any).libp2p,
"getConnections" "getConnections"
@ -102,7 +100,7 @@ describe("Dials", function () {
dialAttemptsForPeerHasStub.returns(false); dialAttemptsForPeerHasStub.returns(false);
}); });
afterEach(function () { afterEachCustom(this, async () => {
dialPeerStub.restore(); dialPeerStub.restore();
getTagNamesForPeerStub.restore(); getTagNamesForPeerStub.restore();
getConnectionsStub.restore(); getConnectionsStub.restore();

View File

@ -10,7 +10,7 @@ import {
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { delay } from "../../src/index.js"; import { afterEachCustom, beforeEachCustom, delay } from "../../src/index.js";
import { tearDownNodes } from "../../src/index.js"; import { tearDownNodes } from "../../src/index.js";
const TEST_TIMEOUT = 20_000; const TEST_TIMEOUT = 20_000;
@ -18,13 +18,11 @@ const TEST_TIMEOUT = 20_000;
describe("Events", function () { describe("Events", function () {
let waku: LightNode; let waku: LightNode;
this.timeout(TEST_TIMEOUT); this.timeout(TEST_TIMEOUT);
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
waku = await createLightNode({ shardInfo: { shards: [0] } }); waku = await createLightNode({ shardInfo: { shards: [0] } });
}); });
afterEach(async () => { afterEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
await tearDownNodes([], waku); await tearDownNodes([], waku);
}); });

View File

@ -10,7 +10,7 @@ import {
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { delay } from "../../src/index.js"; import { afterEachCustom, beforeEachCustom, delay } from "../../src/index.js";
import { tearDownNodes } from "../../src/index.js"; import { tearDownNodes } from "../../src/index.js";
const TEST_TIMEOUT = 20_000; const TEST_TIMEOUT = 20_000;
@ -18,13 +18,11 @@ const TEST_TIMEOUT = 20_000;
describe("Public methods", function () { describe("Public methods", function () {
let waku: LightNode; let waku: LightNode;
this.timeout(TEST_TIMEOUT); this.timeout(TEST_TIMEOUT);
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
waku = await createLightNode({ shardInfo: { shards: [0] } }); waku = await createLightNode({ shardInfo: { shards: [0] } });
}); });
afterEach(async () => { afterEachCustom(this, async () => {
this.timeout(TEST_TIMEOUT);
await tearDownNodes([], waku); await tearDownNodes([], waku);
}); });
it("addEventListener with correct event", async function () { it("addEventListener with correct event", async function () {

View File

@ -2,17 +2,21 @@ import { createLightNode, LightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import sinon, { SinonSpy } from "sinon"; import sinon, { SinonSpy } from "sinon";
import { tearDownNodes } from "../src/index.js"; import {
afterEachCustom,
beforeEachCustom,
tearDownNodes
} from "../src/index.js";
describe("Create node", () => { describe("Create node", function () {
let waku: LightNode; let waku: LightNode;
let consoleInfoSpy: SinonSpy; let consoleInfoSpy: SinonSpy;
beforeEach(() => { beforeEachCustom(this, async () => {
consoleInfoSpy = sinon.spy(console as any, "info"); consoleInfoSpy = sinon.spy(console as any, "info");
}); });
afterEach(async () => { afterEachCustom(this, async () => {
consoleInfoSpy.restore(); consoleInfoSpy.restore();
sinon.restore(); sinon.restore();
await tearDownNodes([], waku); await tearDownNodes([], waku);

View File

@ -6,6 +6,7 @@ import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
ServiceNode, ServiceNode,
@ -16,8 +17,7 @@ describe("ENR Interop: ServiceNode", function () {
let waku: RelayNode; let waku: RelayNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -25,6 +25,8 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
@ -41,20 +43,18 @@ const TestEncoder = createEncoder({
}); });
const TestDecoder = createDecoder(TestContentTopic); const TestDecoder = createDecoder(TestContentTopic);
describe("Waku Message Ephemeral field", () => { describe("Waku Message Ephemeral field", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15_000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: true, lightpush: true,

View File

@ -6,7 +6,11 @@ import {
import { utf8ToBytes } from "@waku/sdk"; import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { ServiceNodesFleet } from "../../src/index.js"; import {
afterEachCustom,
beforeEachCustom,
ServiceNodesFleet
} from "../../src/index.js";
import { import {
runMultipleNodes, runMultipleNodes,
@ -25,14 +29,14 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet; let serviceNodes: ServiceNodesFleet;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [serviceNodes, waku] = await runMultipleNodes(this.ctx, [
[serviceNodes, waku] = await runMultipleNodes(this, [DefaultPubsubTopic]); DefaultPubsubTopic
]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await teardownNodesWithRedundancy(serviceNodes, waku); await teardownNodesWithRedundancy(serviceNodes, waku);
}); });

View File

@ -9,6 +9,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
ServiceNodesFleet, ServiceNodesFleet,
TEST_STRING, TEST_STRING,
@ -32,14 +34,14 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet; let serviceNodes: ServiceNodesFleet;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [serviceNodes, waku] = await runMultipleNodes(this.ctx, [
[serviceNodes, waku] = await runMultipleNodes(this, [DefaultPubsubTopic]); DefaultPubsubTopic
]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await teardownNodesWithRedundancy(serviceNodes, waku); await teardownNodesWithRedundancy(serviceNodes, waku);
}); });

View File

@ -17,6 +17,8 @@ import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
@ -58,10 +60,9 @@ describe("Waku Filter V2: Multiple PubsubTopics", function () {
}); });
const customDecoder2 = createDecoder(customContentTopic2, singleShardInfo2); const customDecoder2 = createDecoder(customContentTopic2, singleShardInfo2);
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[nwaku, waku] = await runNodes( [nwaku, waku] = await runNodes(
this, this.ctx,
[customPubsubTopic1, customPubsubTopic2], [customPubsubTopic1, customPubsubTopic2],
shardInfo shardInfo
); );
@ -71,8 +72,7 @@ describe("Waku Filter V2: Multiple PubsubTopics", function () {
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -229,10 +229,9 @@ describe("Waku Filter V2 (Autosharding): Multiple PubsubTopics", function () {
shard: contentTopicToShardIndex(customContentTopic2) shard: contentTopicToShardIndex(customContentTopic2)
}); });
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[nwaku, waku] = await runNodes( [nwaku, waku] = await runNodes(
this, this.ctx,
[autoshardingPubsubTopic1, autoshardingPubsubTopic2], [autoshardingPubsubTopic1, autoshardingPubsubTopic2],
contentTopicInfo contentTopicInfo
); );
@ -242,8 +241,7 @@ describe("Waku Filter V2 (Autosharding): Multiple PubsubTopics", function () {
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -396,10 +394,9 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () {
}); });
const customDecoder2 = createDecoder(customContentTopic2, customPubsubTopic2); const customDecoder2 = createDecoder(customContentTopic2, customPubsubTopic2);
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[nwaku, waku] = await runNodes( [nwaku, waku] = await runNodes(
this, this.ctx,
[customPubsubTopic1, customPubsubTopic2], [customPubsubTopic1, customPubsubTopic2],
{ {
clusterId: 3, clusterId: 3,
@ -410,8 +407,7 @@ describe("Waku Filter V2 (Named sharding): Multiple PubsubTopics", function () {
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });

View File

@ -7,6 +7,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -28,15 +30,13 @@ describe("Waku Filter V2: Ping", function () {
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [DefaultPubsubTopic]);
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -9,6 +9,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
@ -32,15 +34,13 @@ describe("Waku Filter V2: FilterPush", function () {
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [DefaultPubsubTopic]);
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -16,6 +16,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
generateTestData, generateTestData,
isNwakuAtLeast, isNwakuAtLeast,
@ -44,18 +46,14 @@ describe("Waku Filter V2: Subscribe: Single Service Node", function () {
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [DefaultPubsubTopic]);
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
// Nwaku subscribe to the default pubsub topic
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });

View File

@ -5,6 +5,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
generateTestData, generateTestData,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
@ -27,9 +29,8 @@ describe("Waku Filter V2: Unsubscribe", function () {
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [DefaultPubsubTopic]);
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
messageCollector = new MessageCollector(); messageCollector = new MessageCollector();
@ -37,8 +38,7 @@ describe("Waku Filter V2: Unsubscribe", function () {
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -15,6 +15,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
generateTestData, generateTestData,
isNwakuAtLeast, isNwakuAtLeast,
@ -39,18 +41,16 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet; let serviceNodes: ServiceNodesFleet;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[serviceNodes, waku] = await runMultipleNodes( [serviceNodes, waku] = await runMultipleNodes(
this, this.ctx,
[DefaultPubsubTopic], [DefaultPubsubTopic],
strictCheckNodes strictCheckNodes
); );
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await teardownNodesWithRedundancy(serviceNodes, waku); await teardownNodesWithRedundancy(serviceNodes, waku);
}); });

View File

@ -7,7 +7,12 @@ import {
import { utf8ToBytes } from "@waku/sdk"; import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { generateTestData, ServiceNodesFleet } from "../../src/index.js"; import {
afterEachCustom,
beforeEachCustom,
generateTestData,
ServiceNodesFleet
} from "../../src/index.js";
import { import {
messagePayload, messagePayload,
@ -27,14 +32,14 @@ const runTests = (strictCheckNodes: boolean): void => {
let serviceNodes: ServiceNodesFleet; let serviceNodes: ServiceNodesFleet;
let subscription: IFilterSubscription; let subscription: IFilterSubscription;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [serviceNodes, waku] = await runMultipleNodes(this.ctx, [
[serviceNodes, waku] = await runMultipleNodes(this, [DefaultPubsubTopic]); DefaultPubsubTopic
]);
subscription = await waku.filter.createSubscription(); subscription = await waku.filter.createSubscription();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await teardownNodesWithRedundancy(serviceNodes, waku); await teardownNodesWithRedundancy(serviceNodes, waku);
}); });

View File

@ -17,7 +17,13 @@ import { expect } from "chai";
import fc from "fast-check"; import fc from "fast-check";
import Sinon from "sinon"; import Sinon from "sinon";
import { makeLogFileName, ServiceNode, tearDownNodes } from "../src/index.js"; import {
afterEachCustom,
beforeEachCustom,
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../src/index.js";
describe("getConnectedPeersForProtocolAndShard", function () { describe("getConnectedPeersForProtocolAndShard", function () {
let waku: LightNode; let waku: LightNode;
@ -25,14 +31,12 @@ describe("getConnectedPeersForProtocolAndShard", function () {
let serviceNode2: ServiceNode; let serviceNode2: ServiceNode;
const contentTopic = "/test/2/waku-light-push/utf8"; const contentTopic = "/test/2/waku-light-push/utf8";
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); serviceNode1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
serviceNode1 = new ServiceNode(makeLogFileName(this) + "1"); serviceNode2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
serviceNode2 = new ServiceNode(makeLogFileName(this) + "2");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([serviceNode1, serviceNode2], waku); await tearDownNodes([serviceNode1, serviceNode2], waku);
}); });
@ -420,8 +424,7 @@ describe("getPeers", function () {
let nonBootstrapPeers: Peer[]; let nonBootstrapPeers: Peer[];
let allPeers: Peer[]; let allPeers: Peer[];
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(10_000);
waku = await createLightNode(); waku = await createLightNode();
peerStore = waku.libp2p.peerStore; peerStore = waku.libp2p.peerStore;
connectionManager = waku.libp2p.components.connectionManager; connectionManager = waku.libp2p.components.connectionManager;
@ -537,7 +540,7 @@ describe("getPeers", function () {
}); });
}); });
this.afterEach(function () { afterEachCustom(this, async () => {
Sinon.restore(); Sinon.restore();
}); });

View File

@ -9,6 +9,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
generateRandomUint8Array, generateRandomUint8Array,
ServiceNodesFleet, ServiceNodesFleet,
TEST_STRING TEST_STRING
@ -33,10 +35,9 @@ const runTests = (strictNodeCheck: boolean): void => {
let waku: LightNode; let waku: LightNode;
let serviceNodes: ServiceNodesFleet; let serviceNodes: ServiceNodesFleet;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[serviceNodes, waku] = await runMultipleNodes( [serviceNodes, waku] = await runMultipleNodes(
this, this.ctx,
[DefaultPubsubTopic], [DefaultPubsubTopic],
strictNodeCheck, strictNodeCheck,
undefined, undefined,
@ -45,8 +46,7 @@ const runTests = (strictNodeCheck: boolean): void => {
); );
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await teardownNodesWithRedundancy(serviceNodes, waku); await teardownNodesWithRedundancy(serviceNodes, waku);
}); });

View File

@ -9,6 +9,8 @@ import { utf8ToBytes } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
generateRandomUint8Array, generateRandomUint8Array,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
@ -30,16 +32,14 @@ describe("Waku Light Push: Single Node", function () {
let nwaku: ServiceNode; let nwaku: ServiceNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [DefaultPubsubTopic]);
[nwaku, waku] = await runNodes(this, [DefaultPubsubTopic]);
messageCollector = new MessageCollector(nwaku); messageCollector = new MessageCollector(nwaku);
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -18,6 +18,8 @@ import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
ServiceNode, ServiceNode,
@ -52,10 +54,9 @@ describe("Waku Light Push : Multiple PubsubTopics", function () {
let nimPeerId: PeerId; let nimPeerId: PeerId;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[nwaku, waku] = await runNodes( [nwaku, waku] = await runNodes(
this, this.ctx,
[ [
singleShardInfoToPubsubTopic(singleShardInfo1), singleShardInfoToPubsubTopic(singleShardInfo1),
singleShardInfoToPubsubTopic(singleShardInfo2) singleShardInfoToPubsubTopic(singleShardInfo2)
@ -66,8 +67,7 @@ describe("Waku Light Push : Multiple PubsubTopics", function () {
nimPeerId = await nwaku.getPeerId(); nimPeerId = await nwaku.getPeerId();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -211,10 +211,9 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
let nimPeerId: PeerId; let nimPeerId: PeerId;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
[nwaku, waku] = await runNodes( [nwaku, waku] = await runNodes(
this, this.ctx,
[autoshardingPubsubTopic1, autoshardingPubsubTopic2], [autoshardingPubsubTopic1, autoshardingPubsubTopic2],
shardInfo shardInfo
); );
@ -222,8 +221,7 @@ describe("Waku Light Push (Autosharding): Multiple PubsubTopics", function () {
nimPeerId = await nwaku.getPeerId(); nimPeerId = await nwaku.getPeerId();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -368,9 +366,8 @@ describe("Waku Light Push (named sharding): Multiple PubsubTopics", function ()
let nimPeerId: PeerId; let nimPeerId: PeerId;
this.beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); [nwaku, waku] = await runNodes(this.ctx, [
[nwaku, waku] = await runNodes(this, [
autoshardingPubsubTopic1, autoshardingPubsubTopic1,
autoshardingPubsubTopic2 autoshardingPubsubTopic2
]); ]);
@ -378,8 +375,7 @@ describe("Waku Light Push (named sharding): Multiple PubsubTopics", function ()
nimPeerId = await nwaku.getPeerId(); nimPeerId = await nwaku.getPeerId();
}); });
this.afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });

View File

@ -1,6 +1,6 @@
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName } from "../src/index.js"; import { beforeEachCustom, makeLogFileName } from "../src/index.js";
describe("This", function () { describe("This", function () {
describe("Is", function () { describe("Is", function () {
@ -11,8 +11,8 @@ describe("This", function () {
describe("Is also", function () { describe("Is also", function () {
let testName: string; let testName: string;
beforeEach(function () { beforeEachCustom(this, async () => {
testName = makeLogFileName(this); testName = makeLogFileName(this.ctx);
}); });
it("A test", function () { it("A test", function () {
expect(testName).to.equal("This_Is_also_A_test"); expect(testName).to.equal("This_Is_also_A_test");

View File

@ -7,6 +7,8 @@ import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised"; import chaiAsPromised from "chai-as-promised";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
@ -20,13 +22,11 @@ describe("Metadata Protocol", function () {
let waku: LightNode; let waku: LightNode;
let nwaku1: ServiceNode; let nwaku1: ServiceNode;
beforeEach(function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku1 = new ServiceNode(makeLogFileName(this) + "1");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku1], waku); await tearDownNodes([nwaku1], waku);
}); });

View File

@ -9,6 +9,8 @@ import { expect } from "chai";
import Sinon, { SinonSpy, SinonStub } from "sinon"; import Sinon, { SinonSpy, SinonStub } from "sinon";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
@ -21,8 +23,7 @@ describe("multiaddr: dialing", function () {
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
let isPeerTopicConfigured: SinonStub; let isPeerTopicConfigured: SinonStub;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
@ -54,9 +55,8 @@ describe("multiaddr: dialing", function () {
let peerId: PeerId; let peerId: PeerId;
let multiaddr: Multiaddr; let multiaddr: Multiaddr;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(10_000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start(); await nwaku.start();
waku = await createLightNode(); waku = await createLightNode();
@ -72,7 +72,7 @@ describe("multiaddr: dialing", function () {
dialPeerSpy = Sinon.spy(waku.connectionManager as any, "dialPeer"); dialPeerSpy = Sinon.spy(waku.connectionManager as any, "dialPeer");
}); });
afterEach(function () { afterEachCustom(this, async () => {
dialPeerSpy.restore(); dialPeerSpy.restore();
}); });

View File

@ -16,6 +16,8 @@ import {
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
@ -23,19 +25,18 @@ import {
waitForRemotePeerWithCodec waitForRemotePeerWithCodec
} from "../src/index.js"; } from "../src/index.js";
describe("Peer Exchange", () => { describe("Peer Exchange", function () {
describe("Locally Run Nodes", () => { describe("Locally Run Nodes", () => {
let waku: LightNode; let waku: LightNode;
let nwaku1: ServiceNode; let nwaku1: ServiceNode;
let nwaku2: ServiceNode; let nwaku2: ServiceNode;
beforeEach(function () { beforeEachCustom(this, async () => {
nwaku1 = new ServiceNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new ServiceNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku1, nwaku2], waku); await tearDownNodes([nwaku1, nwaku2], waku);
}); });
@ -126,9 +127,9 @@ describe("Peer Exchange", () => {
let nwaku1: ServiceNode; let nwaku1: ServiceNode;
let nwaku2: ServiceNode; let nwaku2: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
nwaku1 = new ServiceNode(makeLogFileName(this) + "1"); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new ServiceNode(makeLogFileName(this) + "2"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
}); });
tests({ tests({

View File

@ -8,14 +8,13 @@ import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange";
import { createLightNode, DefaultPubsubTopic } from "@waku/sdk"; import { createLightNode, DefaultPubsubTopic } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { tearDownNodes } from "../src"; import { afterEachCustom, tearDownNodes } from "../src";
describe("Peer Exchange", () => { describe("Peer Exchange", () => {
describe("Auto Discovery", function () { describe("Auto Discovery", function () {
let waku: LightNode; let waku: LightNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], waku); await tearDownNodes([], waku);
}); });

View File

@ -18,6 +18,8 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
@ -31,8 +33,7 @@ describe("Waku Relay", function () {
let waku1: RelayNode; let waku1: RelayNode;
let waku2: RelayNode; let waku2: RelayNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(10000);
log.info("Starting JS Waku instances"); log.info("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
@ -53,8 +54,7 @@ describe("Waku Relay", function () {
log.info("before each hook done"); log.info("before each hook done");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2]); await tearDownNodes([], [waku1, waku2]);
}); });

View File

@ -6,7 +6,9 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
base64ToUtf8, base64ToUtf8,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
@ -23,14 +25,13 @@ describe("Waku Relay, Interop", function () {
let waku: RelayNode; let waku: RelayNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(30000);
waku = await createRelayNode({ waku = await createRelayNode({
staticNoiseKey: NOISE_KEY_1 staticNoiseKey: NOISE_KEY_1
}); });
await waku.start(); await waku.start();
nwaku = new ServiceNode(this.test?.ctx?.currentTest?.title + ""); nwaku = new ServiceNode(this.ctx.test?.ctx?.currentTest?.title + "");
await nwaku.start({ relay: true }); await nwaku.start({ relay: true });
await waku.dial(await nwaku.getMultiaddrWithId()); await waku.dial(await nwaku.getMultiaddrWithId());
@ -40,8 +41,7 @@ describe("Waku Relay, Interop", function () {
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
@ -108,7 +108,7 @@ describe("Waku Relay, Interop", function () {
let waku2: RelayNode; let waku2: RelayNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
await tearDownNodes(nwaku, [waku1, waku2]); await tearDownNodes(nwaku, [waku1, waku2]);
}); });

View File

@ -21,6 +21,7 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
MessageCollector, MessageCollector,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
@ -67,8 +68,7 @@ describe("Waku Relay, multiple pubsub topics", function () {
const customDecoder2 = createDecoder(customContentTopic2, singleShardInfo2); const customDecoder2 = createDecoder(customContentTopic2, singleShardInfo2);
const shardInfoBothShards: ShardInfo = { clusterId: 3, shards: [1, 2] }; const shardInfoBothShards: ShardInfo = { clusterId: 3, shards: [1, 2] };
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2, waku3]); await tearDownNodes([], [waku1, waku2, waku3]);
}); });
@ -360,8 +360,7 @@ describe("Waku Relay (Autosharding), multiple pubsub topics", function () {
contentTopics: [customContentTopic1, customContentTopic2] contentTopics: [customContentTopic1, customContentTopic2]
}; };
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2, waku3]); await tearDownNodes([], [waku1, waku2, waku3]);
}); });
@ -671,8 +670,7 @@ describe("Waku Relay (named sharding), multiple pubsub topics", function () {
}); });
const customDecoder2 = createDecoder(customContentTopic2, customPubsubTopic2); const customDecoder2 = createDecoder(customContentTopic2, customPubsubTopic2);
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2, waku3]); await tearDownNodes([], [waku1, waku2, waku3]);
}); });

View File

@ -5,6 +5,8 @@ import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
generateRandomUint8Array, generateRandomUint8Array,
MessageCollector, MessageCollector,
@ -29,8 +31,7 @@ describe("Waku Relay, Publish", function () {
let waku2: RelayNode; let waku2: RelayNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(10000);
log.info("Starting JS Waku instances"); log.info("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ createRelayNode({
@ -52,8 +53,7 @@ describe("Waku Relay, Publish", function () {
await waku2.relay.subscribe([TestDecoder], messageCollector.callback); await waku2.relay.subscribe([TestDecoder], messageCollector.callback);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2]); await tearDownNodes([], [waku1, waku2]);
}); });

View File

@ -5,6 +5,8 @@ import { utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
generateTestData, generateTestData,
MessageCollector, MessageCollector,
NOISE_KEY_1, NOISE_KEY_1,
@ -28,8 +30,7 @@ describe("Waku Relay, Subscribe", function () {
let waku2: RelayNode; let waku2: RelayNode;
let messageCollector: MessageCollector; let messageCollector: MessageCollector;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(10000);
log.info("Starting JS Waku instances"); log.info("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ createRelayNode({
@ -46,11 +47,10 @@ describe("Waku Relay, Subscribe", function () {
}); });
await waku1.dial(waku2.libp2p.peerId); await waku1.dial(waku2.libp2p.peerId);
log.info("before each hook done"); log.info("before each hook done");
messageCollector = new MessageCollector(this.nwaku); messageCollector = new MessageCollector(this.ctx.nwaku);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2]); await tearDownNodes([], [waku1, waku2]);
}); });

View File

@ -17,6 +17,8 @@ import chaiAsPromised from "chai-as-promised";
import Sinon, { SinonSpy } from "sinon"; import Sinon, { SinonSpy } from "sinon";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
@ -35,15 +37,13 @@ describe("Static Sharding: Peer Management", function () {
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
const clusterId = 18; const clusterId = 18;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku1 = new ServiceNode(makeLogFileName(this) + "1"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
nwaku2 = new ServiceNode(makeLogFileName(this) + "2"); nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3");
nwaku3 = new ServiceNode(makeLogFileName(this) + "3");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku1, nwaku2, nwaku3], waku); await tearDownNodes([nwaku1, nwaku2, nwaku3], waku);
dialPeerSpy && dialPeerSpy.restore(); dialPeerSpy && dialPeerSpy.restore();
}); });
@ -216,15 +216,13 @@ describe("Autosharding: Peer Management", function () {
let dialPeerSpy: SinonSpy; let dialPeerSpy: SinonSpy;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1_auto");
nwaku1 = new ServiceNode(makeLogFileName(this) + "1_auto"); nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2_auto");
nwaku2 = new ServiceNode(makeLogFileName(this) + "2_auto"); nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3_auto");
nwaku3 = new ServiceNode(makeLogFileName(this) + "3_auto");
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku1, nwaku2, nwaku3], waku); await tearDownNodes([nwaku1, nwaku2, nwaku3], waku);
dialPeerSpy && dialPeerSpy.restore(); dialPeerSpy && dialPeerSpy.restore();
}); });

View File

@ -17,6 +17,8 @@ import {
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -37,18 +39,16 @@ const singleShardInfo2: SingleShardInfo = { clusterId: 0, shard: 3 };
const ContentTopic = "/waku/2/content/test.js"; const ContentTopic = "/waku/2/content/test.js";
const ContentTopic2 = "/myapp/1/latest/proto"; const ContentTopic2 = "/myapp/1/latest/proto";
describe("Static Sharding: Running Nodes", () => { describe("Static Sharding: Running Nodes", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15_000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
@ -112,18 +112,16 @@ describe("Static Sharding: Running Nodes", () => {
}); });
}); });
describe("Autosharding: Running Nodes", () => { describe("Autosharding: Running Nodes", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15_000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -5,6 +5,8 @@ import { bytesToUtf8 } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -25,15 +27,13 @@ describe("Waku Store, cursor", function () {
let waku2: LightNode; let waku2: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, [waku, waku2]); await tearDownNodes(nwaku, [waku, waku2]);
}); });

View File

@ -3,6 +3,8 @@ import { IMessage, type LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -21,16 +23,14 @@ describe("Waku Store, error handling", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
waku = await startAndConnectLightNode(nwaku); waku = await startAndConnectLightNode(nwaku);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -19,6 +19,8 @@ import { expect } from "chai";
import { equals } from "uint8arrays/equals"; import { equals } from "uint8arrays/equals";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
MessageCollector, MessageCollector,
@ -48,15 +50,13 @@ describe("Waku Store, general", function () {
let waku2: LightNode; let waku2: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, [waku, waku2]); await tearDownNodes(nwaku, [waku, waku2]);
}); });

View File

@ -9,6 +9,8 @@ import {
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
ServiceNode, ServiceNode,
@ -39,9 +41,8 @@ describe("Waku Store, custom pubsub topic", function () {
let nwaku: ServiceNode; let nwaku: ServiceNode;
let nwaku2: ServiceNode; let nwaku2: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2], pubsubTopic: [customShardedPubsubTopic1, customShardedPubsubTopic2],
@ -54,8 +55,7 @@ describe("Waku Store, custom pubsub topic", function () {
]); ]);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -215,9 +215,8 @@ describe.skip("Waku Store (Autosharding), custom pubsub topic", function () {
contentTopics: [customContentTopic1, customContentTopic2] contentTopics: [customContentTopic1, customContentTopic2]
}; };
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
store: true, store: true,
pubsubTopic: [autoshardingPubsubTopic1, autoshardingPubsubTopic2], pubsubTopic: [autoshardingPubsubTopic1, autoshardingPubsubTopic2],
@ -230,8 +229,7 @@ describe.skip("Waku Store (Autosharding), custom pubsub topic", function () {
]); ]);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });
@ -350,15 +348,13 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
customShardedPubsubTopic2 customShardedPubsubTopic2
); );
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000);
const shardInfo = singleShardInfosToShardInfo([ const shardInfo = singleShardInfosToShardInfo([
customShardInfo1, customShardInfo1,
customShardInfo2 customShardInfo2
]); ]);
nwaku = new ServiceNode(makeLogFileName(this)); nwaku = new ServiceNode(makeLogFileName(this.ctx));
await nwaku.start({ await nwaku.start({
store: true, store: true,
relay: true, relay: true,
@ -377,8 +373,7 @@ describe("Waku Store (named sharding), custom pubsub topic", function () {
); );
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([nwaku, nwaku2], waku); await tearDownNodes([nwaku, nwaku2], waku);
}); });

View File

@ -4,6 +4,8 @@ import { DefaultPubsubTopic } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -23,15 +25,13 @@ describe("Waku Store, order", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -3,6 +3,8 @@ import type { LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -20,15 +22,13 @@ describe("Waku Store, page size", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -3,6 +3,8 @@ import type { IMessage, LightNode } from "@waku/interfaces";
import { DefaultPubsubTopic } from "@waku/interfaces"; import { DefaultPubsubTopic } from "@waku/interfaces";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -21,15 +23,13 @@ describe("Waku Store, sorting", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -2,6 +2,8 @@ import type { IMessage, LightNode } from "@waku/interfaces";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
ServiceNode, ServiceNode,
tearDownNodes tearDownNodes
@ -19,15 +21,13 @@ describe("Waku Store, time filter", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ store: true, lightpush: true, relay: true }); await nwaku.start({ store: true, lightpush: true, relay: true });
await nwaku.ensureSubscriptions(); await nwaku.ensureSubscriptions();
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -11,6 +11,8 @@ import chai, { expect } from "chai";
import chaiAsPromised from "chai-as-promised"; import chaiAsPromised from "chai-as-promised";
import { import {
afterEachCustom,
beforeEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
@ -24,13 +26,12 @@ const TestContentTopic = "/test/1/waku-filter";
const TestEncoder = createEncoder({ contentTopic: TestContentTopic }); const TestEncoder = createEncoder({ contentTopic: TestContentTopic });
const TestDecoder = createDecoder(TestContentTopic); const TestDecoder = createDecoder(TestContentTopic);
describe("Util: toAsyncIterator: Filter", () => { describe("Util: toAsyncIterator: Filter", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(15000); nwaku = new ServiceNode(makeLogFileName(this.ctx));
nwaku = new ServiceNode(makeLogFileName(this));
await nwaku.start({ await nwaku.start({
filter: true, filter: true,
lightpush: true, lightpush: true,
@ -45,8 +46,7 @@ describe("Util: toAsyncIterator: Filter", () => {
await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]); await waitForRemotePeer(waku, [Protocols.Filter, Protocols.LightPush]);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(10000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -6,6 +6,7 @@ import { createRelayNode } from "@waku/sdk/relay";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
delay, delay,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
@ -18,8 +19,7 @@ describe("Wait for remote peer", function () {
let waku2: LightNode; let waku2: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, [waku1, waku2]); await tearDownNodes(nwaku, [waku1, waku2]);
}); });

View File

@ -4,14 +4,18 @@ import { LightNode } from "@waku/interfaces";
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { makeLogFileName, ServiceNode, tearDownNodes } from "../src/index.js"; import {
afterEachCustom,
makeLogFileName,
ServiceNode,
tearDownNodes
} from "../src/index.js";
describe("Use static and several ENR trees for bootstrap", function () { describe("Use static and several ENR trees for bootstrap", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });

View File

@ -21,6 +21,8 @@ import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
import { expect } from "chai"; import { expect } from "chai";
import { import {
afterEachCustom,
beforeEachCustom,
makeLogFileName, makeLogFileName,
NOISE_KEY_1, NOISE_KEY_1,
NOISE_KEY_2, NOISE_KEY_2,
@ -37,8 +39,7 @@ describe("Waku Dial [node only]", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
@ -102,8 +103,7 @@ describe("Waku Dial [node only]", function () {
let waku: LightNode; let waku: LightNode;
let nwaku: ServiceNode; let nwaku: ServiceNode;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes(nwaku, waku); await tearDownNodes(nwaku, waku);
}); });
@ -158,17 +158,16 @@ describe("Waku Dial [node only]", function () {
}); });
}); });
describe("Decryption Keys", () => { describe("Decryption Keys", function () {
afterEach(function () { afterEachCustom(this, async () => {
if (this.currentTest?.state === "failed") { if (this.ctx.currentTest?.state === "failed") {
console.log(`Test failed, log file name is ${makeLogFileName(this)}`); console.log(`Test failed, log file name is ${makeLogFileName(this.ctx)}`);
} }
}); });
let waku1: RelayNode; let waku1: RelayNode;
let waku2: RelayNode; let waku2: RelayNode;
beforeEach(async function () { beforeEachCustom(this, async () => {
this.timeout(5000);
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
waku.start().then(() => waku) waku.start().then(() => waku)
@ -190,8 +189,7 @@ describe("Decryption Keys", () => {
]); ]);
}); });
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2]); await tearDownNodes([], [waku1, waku2]);
}); });
@ -228,12 +226,11 @@ describe("Decryption Keys", () => {
}); });
}); });
describe("User Agent", () => { describe("User Agent", function () {
let waku1: Waku; let waku1: Waku;
let waku2: Waku; let waku2: Waku;
afterEach(async function () { afterEachCustom(this, async () => {
this.timeout(15000);
await tearDownNodes([], [waku1, waku2]); await tearDownNodes([], [waku1, waku2]);
}); });