Skip to content

Commit

Permalink
adjust after test with nwaku 25
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarbu15 committed Feb 21, 2024
1 parent a22fc6c commit cfd2120
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 64 deletions.
16 changes: 9 additions & 7 deletions packages/tests/src/utils/custom_mocha_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const log = new Logger("test:mocha-hook");
function withGracefulTimeout(
asyncOperation: () => Promise<void>,
doneCallback: (error?: unknown) => void,
timeoutDuration: number = MOCHA_HOOK_MAX_TIMEOUT
timeoutDuration = MOCHA_HOOK_MAX_TIMEOUT
): void {
let operationCompleted = false;

Expand Down Expand Up @@ -45,24 +45,26 @@ function withGracefulTimeout(

export const beforeEachCustom = function (
suite: Suite,
cb: () => Promise<void>
cb: () => Promise<void>,
timeout = MOCHA_HOOK_MAX_TIMEOUT
): void {
const timeoutBefore = suite.timeout();
suite.timeout(MOCHA_HOOK_MAX_TIMEOUT);
suite.timeout(timeout);
suite.beforeEach((done) => {
withGracefulTimeout(cb, done);
withGracefulTimeout(cb, done, timeout);
});
suite.timeout(timeoutBefore); // restore timeout to the original value
};

export const afterEachCustom = function (
suite: Suite,
cb: () => Promise<void>
cb: () => Promise<void>,
timeout = MOCHA_HOOK_MAX_TIMEOUT
): void {
const timeoutBefore = suite.timeout();
suite.timeout(MOCHA_HOOK_MAX_TIMEOUT);
suite.timeout(timeout);
suite.afterEach((done) => {
withGracefulTimeout(cb, done);
withGracefulTimeout(cb, done, timeout);
});
suite.timeout(timeoutBefore); // restore timeout to the original value
};
5 changes: 3 additions & 2 deletions packages/tests/tests/peer-exchange/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const log = new Logger("test:pe");
const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })];

describe("Peer Exchange", function () {
this.timeout(100_000);
this.timeout(150_000);
let waku: LightNode;
let nwaku1: ServiceNode;
let nwaku2: ServiceNode;
Expand Down Expand Up @@ -96,7 +96,8 @@ describe("Peer Exchange", function () {
expect(connected_bootstram.length).to.eq(1);
});

it("new peer added after a peer was already found", async function () {
// will be skipped until https://github.com/waku-org/js-waku/issues/1860 is fixed
it.skip("new peer added after a peer was already found", async function () {
waku = await createLightNode({
libp2p: {
peerDiscovery: [
Expand Down
114 changes: 59 additions & 55 deletions packages/tests/tests/peer-exchange/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const log = new Logger("test:pe");

const pubsubTopic = [singleShardInfoToPubsubTopic({ clusterId: 0, shard: 2 })];

describe("Query", function () {
describe("Peer Exchange Query", function () {
this.timeout(30_000);
let waku: LightNode;
let nwaku1: ServiceNode;
Expand All @@ -40,63 +40,67 @@ describe("Query", function () {
let numPeersToRequest: number;
let peerInfos: PeerInfo[];

beforeEachCustom(this, async () => {
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3");
await nwaku1.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
relay: true
});
nwaku1PeerId = await nwaku1.getPeerId();
await nwaku2.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
discv5BootstrapNode: (await nwaku1.info()).enrUri,
relay: true
});
await nwaku3.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
discv5BootstrapNode: (await nwaku2.info()).enrUri,
relay: true
});
nwaku3MA = await nwaku3.getMultiaddrWithId();
nwaku3PeerId = await nwaku3.getPeerId();
waku = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: [nwaku3MA.toString()] }),
wakuPeerExchangeDiscovery(pubsubTopic)
]
}
});
await waku.start();
await waku.libp2p.dialProtocol(nwaku3MA, PeerExchangeCodec);
await waitForRemotePeerWithCodec(waku, PeerExchangeCodec, nwaku3PeerId);
beforeEachCustom(
this,
async () => {
nwaku1 = new ServiceNode(makeLogFileName(this.ctx) + "1");
nwaku2 = new ServiceNode(makeLogFileName(this.ctx) + "2");
nwaku3 = new ServiceNode(makeLogFileName(this.ctx) + "3");
await nwaku1.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
relay: true
});
nwaku1PeerId = await nwaku1.getPeerId();
await nwaku2.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
discv5BootstrapNode: (await nwaku1.info()).enrUri,
relay: true
});
await nwaku3.start({
pubsubTopic: pubsubTopic,
discv5Discovery: true,
peerExchange: true,
discv5BootstrapNode: (await nwaku2.info()).enrUri,
relay: true
});
nwaku3MA = await nwaku3.getMultiaddrWithId();
nwaku3PeerId = await nwaku3.getPeerId();
waku = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: [nwaku3MA.toString()] }),
wakuPeerExchangeDiscovery(pubsubTopic)
]
}
});
await waku.start();
await waku.libp2p.dialProtocol(nwaku3MA, PeerExchangeCodec);
await waitForRemotePeerWithCodec(waku, PeerExchangeCodec, nwaku3PeerId);

components = waku.libp2p.components as unknown as Libp2pComponents;
peerExchange = new WakuPeerExchange(components, pubsubTopic);
numPeersToRequest = 2;
components = waku.libp2p.components as unknown as Libp2pComponents;
peerExchange = new WakuPeerExchange(components, pubsubTopic);
numPeersToRequest = 2;

// querying the connected peer
peerInfos = [];
while (peerInfos.length != numPeersToRequest) {
try {
peerInfos = (await peerExchange.query({
peerId: nwaku3PeerId,
numPeers: numPeersToRequest
})) as PeerInfo[];
} catch (error) {
log.error("Error encountered, retrying...");
// querying the connected peer
peerInfos = [];
while (peerInfos.length != numPeersToRequest) {
try {
peerInfos = (await peerExchange.query({
peerId: nwaku3PeerId,
numPeers: numPeersToRequest
})) as PeerInfo[];
} catch (error) {
log.error("Error encountered, retrying...");
}
await delay(2000);
}
await delay(2000);
}
});
},
100000
);

afterEachCustom(this, async () => {
await tearDownNodes([nwaku1, nwaku2, nwaku3], waku);
Expand Down

0 comments on commit cfd2120

Please sign in to comment.