mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-05-05 12:23:06 +00:00
chore: update sharding tests
This commit is contained in:
parent
d7d60f2c67
commit
87d09f0f41
@ -27,7 +27,7 @@ const WAKU_SERVICE_NODE_PARAMS =
|
|||||||
const NODE_READY_LOG_LINE = "Node setup complete";
|
const NODE_READY_LOG_LINE = "Node setup complete";
|
||||||
|
|
||||||
export const DOCKER_IMAGE_NAME =
|
export const DOCKER_IMAGE_NAME =
|
||||||
process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.31.0";
|
process.env.WAKUNODE_IMAGE || "wakuorg/nwaku:v0.34.0";
|
||||||
|
|
||||||
const isGoWaku = DOCKER_IMAGE_NAME.includes("go-waku");
|
const isGoWaku = DOCKER_IMAGE_NAME.includes("go-waku");
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import {
|
|||||||
|
|
||||||
// These tests are expected to fail as service nodes now require at least one more connected node: https://github.com/waku-org/nwaku/pull/2951/files
|
// These tests are expected to fail as service nodes now require at least one more connected node: https://github.com/waku-org/nwaku/pull/2951/files
|
||||||
|
|
||||||
describe.only("Waku Light Push: Single Node: Fails as expected", function () {
|
describe("Waku Light Push: Single Node: Fails as expected", function () {
|
||||||
// Set the timeout for all tests in this suite. Can be overwritten at test level
|
// Set the timeout for all tests in this suite. Can be overwritten at test level
|
||||||
this.timeout(15000);
|
this.timeout(15000);
|
||||||
let waku: LightNode;
|
let waku: LightNode;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { LightNode, ProtocolError, Protocols } from "@waku/interfaces";
|
import { LightNode, ProtocolError } from "@waku/interfaces";
|
||||||
import { createEncoder, createLightNode, utf8ToBytes } from "@waku/sdk";
|
import { createEncoder, createLightNode, utf8ToBytes } from "@waku/sdk";
|
||||||
import {
|
import {
|
||||||
contentTopicToPubsubTopic,
|
contentTopicToPubsubTopic,
|
||||||
@ -8,10 +8,8 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
runMultipleNodes,
|
||||||
makeLogFileName,
|
ServiceNodesFleet,
|
||||||
MessageCollector,
|
|
||||||
ServiceNode,
|
|
||||||
tearDownNodes
|
tearDownNodes
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
|
|
||||||
@ -22,41 +20,33 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
this.timeout(50000);
|
this.timeout(50000);
|
||||||
const clusterId = 10;
|
const clusterId = 10;
|
||||||
let waku: LightNode;
|
let waku: LightNode;
|
||||||
let nwaku: ServiceNode;
|
let serviceNodes: ServiceNodesFleet;
|
||||||
let messageCollector: MessageCollector;
|
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
|
||||||
nwaku = new ServiceNode(makeLogFileName(this.ctx));
|
|
||||||
messageCollector = new MessageCollector(nwaku);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEachCustom(this, async () => {
|
afterEachCustom(this, async () => {
|
||||||
await tearDownNodes(nwaku, waku);
|
await tearDownNodes(serviceNodes.nodes, waku);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Different clusters and topics", function () {
|
describe("Different clusters and topics", function () {
|
||||||
// js-waku allows autosharding for cluster IDs different than 1
|
|
||||||
it("Cluster ID 0 - Default/Global Cluster", async function () {
|
it("Cluster ID 0 - Default/Global Cluster", async function () {
|
||||||
const clusterId = 0;
|
const clusterId = 0;
|
||||||
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
||||||
await nwaku.start({
|
|
||||||
store: true,
|
|
||||||
lightpush: true,
|
|
||||||
relay: true,
|
|
||||||
clusterId: clusterId,
|
|
||||||
pubsubTopic: pubsubTopics
|
|
||||||
});
|
|
||||||
|
|
||||||
await nwaku.ensureSubscriptions(pubsubTopics);
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
|
this.ctx,
|
||||||
waku = await createLightNode({
|
{
|
||||||
networkConfig: {
|
clusterId,
|
||||||
clusterId: clusterId,
|
|
||||||
contentTopics: [ContentTopic]
|
contentTopics: [ContentTopic]
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
store: true,
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
|
pubsubTopic: pubsubTopics
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -70,9 +60,10 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2); // Expect 2 successes for 2 nodes
|
||||||
|
console.log("good");
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessagesAutosharding(1, {
|
await serviceNodes.messageCollector.waitForMessagesAutosharding(1, {
|
||||||
contentTopic: ContentTopic
|
contentTopic: ContentTopic
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -81,24 +72,23 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
it("Non TWN Cluster", async function () {
|
it("Non TWN Cluster", async function () {
|
||||||
const clusterId = 5;
|
const clusterId = 5;
|
||||||
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
||||||
await nwaku.start({
|
|
||||||
store: true,
|
|
||||||
lightpush: true,
|
|
||||||
relay: true,
|
|
||||||
clusterId: clusterId,
|
|
||||||
pubsubTopic: pubsubTopics
|
|
||||||
});
|
|
||||||
|
|
||||||
await nwaku.ensureSubscriptions(pubsubTopics);
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
|
this.ctx,
|
||||||
waku = await createLightNode({
|
{
|
||||||
networkConfig: {
|
clusterId,
|
||||||
clusterId: clusterId,
|
|
||||||
contentTopics: [ContentTopic]
|
contentTopics: [ContentTopic]
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
store: true,
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
|
pubsubTopic: pubsubTopics
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -112,9 +102,9 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2); // Expect 2 successes for 2 nodes
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessagesAutosharding(1, {
|
await serviceNodes.messageCollector.waitForMessagesAutosharding(1, {
|
||||||
contentTopic: ContentTopic
|
contentTopic: ContentTopic
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -138,24 +128,23 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
contentTopicToPubsubTopic(ContentTopic, clusterId)
|
contentTopicToPubsubTopic(ContentTopic, clusterId)
|
||||||
];
|
];
|
||||||
|
|
||||||
await nwaku.start({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
store: true,
|
this.ctx,
|
||||||
lightpush: true,
|
{
|
||||||
relay: true,
|
clusterId,
|
||||||
clusterId: clusterId,
|
|
||||||
pubsubTopic: pubsubTopics,
|
|
||||||
contentTopic: [ContentTopic]
|
|
||||||
});
|
|
||||||
|
|
||||||
waku = await createLightNode({
|
|
||||||
networkConfig: {
|
|
||||||
clusterId: clusterId,
|
|
||||||
contentTopics: [ContentTopic]
|
contentTopics: [ContentTopic]
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
|
store: true,
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
lightpush: true,
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
relay: true,
|
||||||
|
pubsubTopic: pubsubTopics,
|
||||||
|
contentTopic: [ContentTopic]
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -169,9 +158,9 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2); // Expect 2 successes for 2 nodes
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessagesAutosharding(1, {
|
await serviceNodes.messageCollector.waitForMessagesAutosharding(1, {
|
||||||
contentTopic: ContentTopic
|
contentTopic: ContentTopic
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -201,24 +190,23 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
contentTopicToPubsubTopic(ContentTopic2, clusterId)
|
contentTopicToPubsubTopic(ContentTopic2, clusterId)
|
||||||
];
|
];
|
||||||
|
|
||||||
await nwaku.start({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
store: true,
|
this.ctx,
|
||||||
lightpush: true,
|
{
|
||||||
relay: true,
|
clusterId,
|
||||||
clusterId: clusterId,
|
|
||||||
pubsubTopic: pubsubTopics,
|
|
||||||
contentTopic: [ContentTopic, ContentTopic2]
|
|
||||||
});
|
|
||||||
|
|
||||||
waku = await createLightNode({
|
|
||||||
networkConfig: {
|
|
||||||
clusterId: clusterId,
|
|
||||||
// For autosharding, we configure multiple pubsub topics by using two content topics that hash to different shards
|
|
||||||
contentTopics: [ContentTopic, ContentTopic2]
|
contentTopics: [ContentTopic, ContentTopic2]
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
store: true,
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
|
pubsubTopic: pubsubTopics,
|
||||||
|
contentTopic: [ContentTopic, ContentTopic2]
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const encoder1 = createEncoder({
|
const encoder1 = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -239,9 +227,9 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
const request1 = await waku.lightPush.send(encoder1, {
|
const request1 = await waku.lightPush.send(encoder1, {
|
||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
expect(request1.successes.length).to.eq(1);
|
expect(request1.successes.length).to.eq(2); // Expect 2 successes for 2 nodes
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessagesAutosharding(1, {
|
await serviceNodes.messageCollector.waitForMessagesAutosharding(1, {
|
||||||
contentTopic: ContentTopic
|
contentTopic: ContentTopic
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -249,9 +237,9 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
const request2 = await waku.lightPush.send(encoder2, {
|
const request2 = await waku.lightPush.send(encoder2, {
|
||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
expect(request2.successes.length).to.eq(1);
|
expect(request2.successes.length).to.eq(2); // Expect 2 successes for 2 nodes
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessagesAutosharding(1, {
|
await serviceNodes.messageCollector.waitForMessagesAutosharding(1, {
|
||||||
contentTopic: ContentTopic
|
contentTopic: ContentTopic
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -259,21 +247,24 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
|
|
||||||
it("using a protocol with unconfigured pubsub topic should fail", async function () {
|
it("using a protocol with unconfigured pubsub topic should fail", async function () {
|
||||||
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
const pubsubTopics = [contentTopicToPubsubTopic(ContentTopic, clusterId)];
|
||||||
await nwaku.start({
|
|
||||||
store: true,
|
|
||||||
lightpush: true,
|
|
||||||
relay: true,
|
|
||||||
clusterId: clusterId,
|
|
||||||
pubsubTopic: pubsubTopics,
|
|
||||||
contentTopic: [ContentTopic]
|
|
||||||
});
|
|
||||||
|
|
||||||
waku = await createLightNode({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
networkConfig: {
|
this.ctx,
|
||||||
clusterId: clusterId,
|
{
|
||||||
|
clusterId,
|
||||||
contentTopics: [ContentTopic]
|
contentTopics: [ContentTopic]
|
||||||
}
|
},
|
||||||
});
|
{
|
||||||
|
store: true,
|
||||||
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
|
pubsubTopic: pubsubTopics,
|
||||||
|
contentTopic: [ContentTopic]
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// use a content topic that is not configured
|
// use a content topic that is not configured
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
@ -288,17 +279,17 @@ describe("Autosharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
if (successes.length > 0 || failures?.length === 0) {
|
if (successes.length > 0 || !failures?.length) {
|
||||||
throw new Error("The request should've thrown an error");
|
throw new Error("The request should've thrown an error");
|
||||||
}
|
}
|
||||||
|
|
||||||
const errors = failures?.map((failure) => failure.error);
|
const errors = failures.map((failure) => failure.error);
|
||||||
expect(errors).to.include(ProtocolError.TOPIC_NOT_CONFIGURED);
|
expect(errors).to.include(ProtocolError.TOPIC_NOT_CONFIGURED);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("start node with empty content topic", async function () {
|
it("start node with empty content topic", async function () {
|
||||||
try {
|
try {
|
||||||
waku = await createLightNode({
|
await createLightNode({
|
||||||
networkConfig: {
|
networkConfig: {
|
||||||
clusterId: clusterId,
|
clusterId: clusterId,
|
||||||
contentTopics: []
|
contentTopics: []
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
LightNode,
|
LightNode,
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
Protocols,
|
|
||||||
ShardInfo,
|
ShardInfo,
|
||||||
SingleShardInfo
|
SingleShardInfo
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
@ -15,10 +14,8 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
afterEachCustom,
|
afterEachCustom,
|
||||||
beforeEachCustom,
|
runMultipleNodes,
|
||||||
makeLogFileName,
|
ServiceNodesFleet,
|
||||||
MessageCollector,
|
|
||||||
ServiceNode,
|
|
||||||
tearDownNodes
|
tearDownNodes
|
||||||
} from "../../src/index.js";
|
} from "../../src/index.js";
|
||||||
|
|
||||||
@ -27,16 +24,10 @@ const ContentTopic = "/waku/2/content/test.js";
|
|||||||
describe("Static Sharding: Running Nodes", function () {
|
describe("Static Sharding: Running Nodes", function () {
|
||||||
this.timeout(15_000);
|
this.timeout(15_000);
|
||||||
let waku: LightNode;
|
let waku: LightNode;
|
||||||
let nwaku: ServiceNode;
|
let serviceNodes: ServiceNodesFleet;
|
||||||
let messageCollector: MessageCollector;
|
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
|
||||||
nwaku = new ServiceNode(makeLogFileName(this.ctx));
|
|
||||||
messageCollector = new MessageCollector(nwaku);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEachCustom(this, async () => {
|
afterEachCustom(this, async () => {
|
||||||
await tearDownNodes(nwaku, waku);
|
await tearDownNodes(serviceNodes.nodes, waku);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Different clusters and shards", function () {
|
describe("Different clusters and shards", function () {
|
||||||
@ -44,20 +35,19 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
const singleShardInfo = { clusterId: 0, shard: 0 };
|
const singleShardInfo = { clusterId: 0, shard: 0 };
|
||||||
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
||||||
|
|
||||||
await nwaku.start({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
store: true,
|
this.ctx,
|
||||||
lightpush: true,
|
shardInfo,
|
||||||
relay: true,
|
{
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
store: true,
|
||||||
});
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
await nwaku.ensureSubscriptions(shardInfoToPubsubTopics(shardInfo));
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
||||||
|
},
|
||||||
waku = await createLightNode({
|
false,
|
||||||
networkConfig: shardInfo
|
2,
|
||||||
});
|
true
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
);
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -71,33 +61,31 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2);
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessages(1, {
|
await serviceNodes.messageCollector.waitForMessages(1, {
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// dedicated test for Default Cluster ID 0
|
|
||||||
it("Cluster ID 0 - Default/Global Cluster", async function () {
|
it("Cluster ID 0 - Default/Global Cluster", async function () {
|
||||||
const singleShardInfo = { clusterId: 0, shard: 1 };
|
const singleShardInfo = { clusterId: 0, shard: 1 };
|
||||||
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
||||||
|
|
||||||
await nwaku.start({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
store: true,
|
this.ctx,
|
||||||
lightpush: true,
|
shardInfo,
|
||||||
relay: true,
|
{
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
store: true,
|
||||||
});
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
await nwaku.ensureSubscriptions(shardInfoToPubsubTopics(shardInfo));
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
||||||
|
},
|
||||||
waku = await createLightNode({
|
false,
|
||||||
networkConfig: shardInfo
|
2,
|
||||||
});
|
true
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
);
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -108,9 +96,9 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2);
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessages(1, {
|
await serviceNodes.messageCollector.waitForMessages(1, {
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -120,33 +108,29 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
for (let i = 0; i < numTest; i++) {
|
for (let i = 0; i < numTest; i++) {
|
||||||
// Random clusterId between 2 and 1000
|
// Random clusterId between 2 and 1000
|
||||||
const clusterId = Math.floor(Math.random() * 999) + 2;
|
const clusterId = Math.floor(Math.random() * 999) + 2;
|
||||||
|
|
||||||
// Random shardId between 1 and 1000
|
// Random shardId between 1 and 1000
|
||||||
const shardId = Math.floor(Math.random() * 1000) + 1;
|
const shardId = Math.floor(Math.random() * 1000) + 1;
|
||||||
|
|
||||||
it(`random static sharding ${
|
it(`random static sharding ${
|
||||||
i + 1
|
i + 1
|
||||||
} - Cluster ID: ${clusterId}, Shard ID: ${shardId}`, async function () {
|
} - Cluster ID: ${clusterId}, Shard ID: ${shardId}`, async function () {
|
||||||
afterEach(async () => {
|
|
||||||
await tearDownNodes(nwaku, waku);
|
|
||||||
});
|
|
||||||
|
|
||||||
const singleShardInfo = { clusterId: clusterId, shard: shardId };
|
const singleShardInfo = { clusterId: clusterId, shard: shardId };
|
||||||
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
const shardInfo = singleShardInfosToShardInfo([singleShardInfo]);
|
||||||
|
|
||||||
await nwaku.start({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
store: true,
|
this.ctx,
|
||||||
lightpush: true,
|
shardInfo,
|
||||||
relay: true,
|
{
|
||||||
clusterId: clusterId,
|
store: true,
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
lightpush: true,
|
||||||
});
|
relay: true,
|
||||||
|
clusterId: clusterId,
|
||||||
waku = await createLightNode({
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
||||||
networkConfig: shardInfo
|
},
|
||||||
});
|
false,
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
2,
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
true
|
||||||
|
);
|
||||||
|
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -157,9 +141,9 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(request.successes.length).to.eq(1);
|
expect(request.successes.length).to.eq(2);
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessages(1, {
|
await serviceNodes.messageCollector.waitForMessages(1, {
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
@ -169,12 +153,14 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
|
|
||||||
describe("Others", function () {
|
describe("Others", function () {
|
||||||
const clusterId = 2;
|
const clusterId = 2;
|
||||||
let shardInfo: ShardInfo;
|
|
||||||
|
|
||||||
const shardInfoFirstShard: ShardInfo = {
|
const shardInfoFirstShard: ShardInfo = {
|
||||||
clusterId: clusterId,
|
clusterId: clusterId,
|
||||||
shards: [2]
|
shards: [2]
|
||||||
};
|
};
|
||||||
|
const shardInfoSecondShard: ShardInfo = {
|
||||||
|
clusterId: clusterId,
|
||||||
|
shards: [3]
|
||||||
|
};
|
||||||
const shardInfoBothShards: ShardInfo = {
|
const shardInfoBothShards: ShardInfo = {
|
||||||
clusterId: clusterId,
|
clusterId: clusterId,
|
||||||
shards: [2, 3]
|
shards: [2, 3]
|
||||||
@ -188,31 +174,21 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
shard: 3
|
shard: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEachCustom(this, async () => {
|
it.only("configure the node with multiple pubsub topics", async function () {
|
||||||
shardInfo = {
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
clusterId: clusterId,
|
this.ctx,
|
||||||
shards: [2]
|
shardInfoBothShards,
|
||||||
};
|
{
|
||||||
|
store: true,
|
||||||
await nwaku.start({
|
lightpush: true,
|
||||||
store: true,
|
relay: true,
|
||||||
lightpush: true,
|
clusterId: clusterId,
|
||||||
relay: true,
|
pubsubTopic: shardInfoToPubsubTopics(shardInfoBothShards)
|
||||||
clusterId: clusterId,
|
},
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)
|
false,
|
||||||
});
|
2,
|
||||||
});
|
true
|
||||||
|
);
|
||||||
afterEachCustom(this, async () => {
|
|
||||||
await tearDownNodes(nwaku, waku);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("configure the node with multiple pubsub topics", async function () {
|
|
||||||
waku = await createLightNode({
|
|
||||||
networkConfig: shardInfoBothShards
|
|
||||||
});
|
|
||||||
await waku.dial(await nwaku.getMultiaddrWithId());
|
|
||||||
await waku.waitForPeers([Protocols.LightPush]);
|
|
||||||
|
|
||||||
const encoder1 = createEncoder({
|
const encoder1 = createEncoder({
|
||||||
contentTopic: ContentTopic,
|
contentTopic: ContentTopic,
|
||||||
@ -227,29 +203,40 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
const request1 = await waku.lightPush.send(encoder1, {
|
const request1 = await waku.lightPush.send(encoder1, {
|
||||||
payload: utf8ToBytes("Hello World2")
|
payload: utf8ToBytes("Hello World2")
|
||||||
});
|
});
|
||||||
expect(request1.successes.length).to.eq(1);
|
expect(request1.successes.length).to.eq(2);
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessages(1, {
|
await serviceNodes.messageCollector.waitForMessages(1, {
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
pubsubTopic: shardInfoToPubsubTopics(shardInfoFirstShard)[0]
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
|
|
||||||
const request2 = await waku.lightPush.send(encoder2, {
|
const request2 = await waku.lightPush.send(encoder2, {
|
||||||
payload: utf8ToBytes("Hello World3")
|
payload: utf8ToBytes("Hello World3")
|
||||||
});
|
});
|
||||||
expect(request2.successes.length).to.eq(1);
|
expect(request2.successes.length).to.eq(2);
|
||||||
expect(
|
expect(
|
||||||
await messageCollector.waitForMessages(1, {
|
await serviceNodes.messageCollector.waitForMessages(1, {
|
||||||
pubsubTopic: shardInfoToPubsubTopics(shardInfo)[0]
|
pubsubTopic: shardInfoToPubsubTopics(shardInfoSecondShard)[0]
|
||||||
})
|
})
|
||||||
).to.eq(true);
|
).to.eq(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("using a protocol with unconfigured pubsub topic should fail", async function () {
|
it("using a protocol with unconfigured pubsub topic should fail", async function () {
|
||||||
this.timeout(15_000);
|
this.timeout(15_000);
|
||||||
waku = await createLightNode({
|
[serviceNodes, waku] = await runMultipleNodes(
|
||||||
networkConfig: shardInfoFirstShard
|
this.ctx,
|
||||||
});
|
shardInfoFirstShard,
|
||||||
|
{
|
||||||
|
store: true,
|
||||||
|
lightpush: true,
|
||||||
|
relay: true,
|
||||||
|
clusterId: clusterId,
|
||||||
|
pubsubTopic: shardInfoToPubsubTopics(shardInfoFirstShard)
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// use a pubsub topic that is not configured
|
// use a pubsub topic that is not configured
|
||||||
const encoder = createEncoder({
|
const encoder = createEncoder({
|
||||||
@ -261,17 +248,17 @@ describe("Static Sharding: Running Nodes", function () {
|
|||||||
payload: utf8ToBytes("Hello World")
|
payload: utf8ToBytes("Hello World")
|
||||||
});
|
});
|
||||||
|
|
||||||
if (successes.length > 0 || failures?.length === 0) {
|
if (successes.length > 0 || !failures?.length) {
|
||||||
throw new Error("The request should've thrown an error");
|
throw new Error("The request should've thrown an error");
|
||||||
}
|
}
|
||||||
|
|
||||||
const errors = failures?.map((failure) => failure.error);
|
const errors = failures.map((failure) => failure.error);
|
||||||
expect(errors).to.include(ProtocolError.TOPIC_NOT_CONFIGURED);
|
expect(errors).to.include(ProtocolError.TOPIC_NOT_CONFIGURED);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("start node with empty shard should fail", async function () {
|
it("start node with empty shard should fail", async function () {
|
||||||
try {
|
try {
|
||||||
waku = await createLightNode({
|
await createLightNode({
|
||||||
networkConfig: { clusterId: clusterId, shards: [] }
|
networkConfig: { clusterId: clusterId, shards: [] }
|
||||||
});
|
});
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user