Skip to content

Commit c1f9471

Browse files
authored
chore: extra reliability tests 2 (#2450)
* chore: add throughput reliability tests * chore: add capability to run all * chore: add network-latency reliability tests * chore: add network-latency reliability tests * chore: add other network reliability tests * chore: add other network reliability tests * chore: fix tc cleanup * chore: refactor common code * chore: refactor common code * chore: refactor common code * chore: refactor common code * chore: refactor common code * chore: refactor common code * chore: refactor common code * chore: fix * chore: fix tests * chore: fix tests
1 parent 0be4861 commit c1f9471

File tree

10 files changed

+407
-478
lines changed

10 files changed

+407
-478
lines changed

.github/workflows/test-reliability.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
- longevity
1313
- high-throughput
1414
- throughput-sizes
15+
- network-latency
16+
- low-bandwidth
17+
- packet-loss
1518
- all
1619

1720
env:
@@ -26,7 +29,7 @@ jobs:
2629
checks: write
2730
strategy:
2831
matrix:
29-
test_type: [longevity, high-throughput, throughput-sizes]
32+
test_type: [longevity, high-throughput, throughput-sizes, network-latency, low-bandwidth, packet-loss]
3033
fail-fast: false
3134
if: ${{ github.event.inputs.test_type == 'all' }}
3235
steps:
@@ -52,6 +55,12 @@ jobs:
5255
npm run test:high-throughput
5356
elif [ "${{ matrix.test_type }}" = "throughput-sizes" ]; then
5457
npm run test:throughput-sizes
58+
elif [ "${{ matrix.test_type }}" = "network-latency" ]; then
59+
npm run test:network-latency
60+
elif [ "${{ matrix.test_type }}" = "low-bandwidth" ]; then
61+
npm run test:low-bandwidth
62+
elif [ "${{ matrix.test_type }}" = "packet-loss" ]; then
63+
npm run test:packet-loss
5564
else
5665
npm run test:longevity
5766
fi
@@ -86,6 +95,12 @@ jobs:
8695
npm run test:high-throughput
8796
elif [ "${{ github.event.inputs.test_type }}" = "throughput-sizes" ]; then
8897
npm run test:throughput-sizes
98+
elif [ "${{ github.event.inputs.test_type }}" = "network-latency" ]; then
99+
npm run test:network-latency
100+
elif [ "${{ github.event.inputs.test_type }}" = "low-bandwidth" ]; then
101+
npm run test:low-bandwidth
102+
elif [ "${{ github.event.inputs.test_type }}" = "packet-loss" ]; then
103+
npm run test:packet-loss
89104
else
90105
npm run test:longevity
91106
fi

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"test:longevity": "npm --prefix packages/reliability-tests run test:longevity",
3737
"test:high-throughput": "npm --prefix packages/reliability-tests run test:high-throughput",
3838
"test:throughput-sizes": "npm --prefix packages/reliability-tests run test:throughput-sizes",
39+
"test:network-latency": "npm --prefix packages/reliability-tests run test:network-latency",
40+
"test:low-bandwidth": "npm --prefix packages/reliability-tests run test:low-bandwidth",
41+
"test:packet-loss": "npm --prefix packages/reliability-tests run test:packet-loss",
3942
"proto": "npm run proto --workspaces --if-present",
4043
"deploy": "node ci/deploy.js",
4144
"doc": "run-s doc:*",

packages/reliability-tests/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"test:longevity": "NODE_ENV=test node ./src/run-tests.js tests/longevity.spec.ts",
4545
"test:high-throughput": "NODE_ENV=test node ./src/run-tests.js tests/high-throughput.spec.ts",
4646
"test:throughput-sizes": "NODE_ENV=test node ./src/run-tests.js tests/throughput-sizes.spec.ts",
47+
"test:network-latency": "NODE_ENV=test node ./src/run-tests.js tests/network-latency.spec.ts",
48+
"test:low-bandwidth": "NODE_ENV=test node ./src/run-tests.js tests/low-bandwidth.spec.ts",
49+
"test:packet-loss": "NODE_ENV=test node ./src/run-tests.js tests/packet-loss.spec.ts",
4750
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
4851
},
4952
"engines": {
Lines changed: 9 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,16 @@
1-
import { LightNode, Protocols } from "@waku/interfaces";
2-
import { createDecoder, createLightNode, utf8ToBytes } from "@waku/sdk";
3-
import {
4-
contentTopicToPubsubTopic,
5-
createRoutingInfo,
6-
delay
7-
} from "@waku/utils";
8-
import { expect } from "chai";
9-
10-
import {
11-
afterEachCustom,
12-
beforeEachCustom,
13-
makeLogFileName,
14-
MessageCollector,
15-
ServiceNode,
16-
tearDownNodes
17-
} from "../../tests/src/index.js";
18-
19-
const ContentTopic = "/waku/2/content/test.high-throughput.js";
20-
const NetworkConfig = { clusterId: 0, numShardsInCluster: 8 };
21-
const RoutingInfo = createRoutingInfo(NetworkConfig, {
22-
contentTopic: ContentTopic
23-
});
1+
import { runTest, setupTest } from "./sharedTestUtils.js";
242

253
describe("High Throughput Messaging", function () {
264
const testDurationMs = 20 * 60 * 1000; // 20 minutes
27-
this.timeout(testDurationMs * 1.1);
28-
let waku: LightNode;
29-
let nwaku: ServiceNode;
30-
let messageCollector: MessageCollector;
31-
32-
beforeEachCustom(this, async () => {
33-
nwaku = new ServiceNode(makeLogFileName(this.ctx));
34-
messageCollector = new MessageCollector(nwaku);
35-
});
36-
37-
afterEachCustom(this, async () => {
38-
await tearDownNodes(nwaku, waku);
39-
});
40-
41-
it("Send/Receive thousands of messages quickly", async function () {
42-
const testStart = new Date();
43-
const testEnd = Date.now() + testDurationMs;
44-
45-
const report: {
46-
messageId: number;
47-
timestamp: string;
48-
sent: boolean;
49-
received: boolean;
50-
error?: string;
51-
}[] = [];
52-
53-
await nwaku.start(
54-
{
55-
store: true,
56-
filter: true,
57-
relay: true,
58-
clusterId: NetworkConfig.clusterId,
59-
numShardsInNetwork: NetworkConfig.numShardsInCluster,
60-
contentTopic: [ContentTopic]
61-
},
62-
{ retries: 3 }
63-
);
64-
65-
await delay(1000);
66-
67-
await nwaku.ensureSubscriptions([
68-
contentTopicToPubsubTopic(
69-
ContentTopic,
70-
NetworkConfig.clusterId,
71-
NetworkConfig.numShardsInCluster
72-
)
73-
]);
74-
75-
waku = await createLightNode({ networkConfig: NetworkConfig });
76-
await waku.start();
77-
await waku.dial(await nwaku.getMultiaddrWithId());
78-
await waku.waitForPeers([Protocols.Filter]);
79-
80-
const decoder = createDecoder(ContentTopic, RoutingInfo);
81-
const hasSubscribed = await waku.filter.subscribe(
82-
[decoder],
83-
messageCollector.callback
84-
);
85-
if (!hasSubscribed) throw new Error("Failed to subscribe from the start.");
86-
87-
let messageId = 0;
88-
89-
// Send messages as fast as possible until testEnd
90-
while (Date.now() < testEnd) {
91-
const now = new Date();
92-
const message = `msg-${messageId}`;
93-
let sent = false;
94-
let received = false;
95-
let err: string | undefined;
96-
97-
try {
98-
await nwaku.sendMessage(
99-
ServiceNode.toMessageRpcQuery({
100-
contentTopic: ContentTopic,
101-
payload: utf8ToBytes(message)
102-
}),
103-
RoutingInfo
104-
);
105-
sent = true;
106-
107-
received = await messageCollector.waitForMessages(1, {
108-
timeoutDuration: 2000
109-
});
110-
111-
if (received) {
112-
messageCollector.verifyReceivedMessage(0, {
113-
expectedMessageText: message,
114-
expectedContentTopic: ContentTopic,
115-
expectedPubsubTopic: RoutingInfo.pubsubTopic
116-
});
117-
}
118-
} catch (e: any) {
119-
err = e.message || String(e);
120-
}
121-
122-
report.push({
123-
messageId,
124-
timestamp: now.toISOString(),
125-
sent,
126-
received,
127-
error: err
128-
});
129-
130-
messageId++;
131-
messageCollector.list = []; // clearing the message collector
132-
}
133-
134-
const failedMessages = report.filter(
135-
(m) => !m.sent || !m.received || m.error
136-
);
137-
138-
console.log("\n=== High Throughput Test Summary ===");
139-
console.log("Start time:", testStart.toISOString());
140-
console.log("End time:", new Date().toISOString());
141-
console.log("Total messages:", report.length);
142-
console.log("Failures:", failedMessages.length);
5+
const testContext = {};
1436

144-
if (failedMessages.length > 0) {
145-
console.log("\n--- Failed Messages ---");
146-
for (const fail of failedMessages) {
147-
console.log(
148-
`#${fail.messageId} @ ${fail.timestamp} | sent: ${fail.sent} | received: ${fail.received} | error: ${fail.error || "N/A"}`
149-
);
150-
}
151-
}
7+
setupTest(this, testContext);
1528

153-
expect(
154-
failedMessages.length,
155-
`Some messages failed: ${failedMessages.length}`
156-
).to.eq(0);
9+
runTest({
10+
testContext: testContext,
11+
testDurationMs: testDurationMs,
12+
testName: "High Throughput Messaging",
13+
messageGenerator: (messageId: number) => `High-Throughput-${messageId}`,
14+
delayBetweenMessagesMs: 0
15715
});
15816
});

0 commit comments

Comments
 (0)