Improve output on error for store and light push

This commit is contained in:
Franck Royer 2022-04-20 14:22:21 +10:00
parent 34f65b8587
commit b048c56499
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 51 additions and 30 deletions

View File

@ -16,8 +16,6 @@ export default function runAll(nodes) {
}); });
it("Connect", async function () { it("Connect", async function () {
// This test depends on fleets.status.im being online.
// This dependence must be removed once DNS discovery is implemented
this.timeout(20000); this.timeout(20000);
const peerIds = nodes.map((a) => { const peerIds = nodes.map((a) => {
@ -51,8 +49,6 @@ export default function runAll(nodes) {
}); });
it("Relay", async function () { it("Relay", async function () {
// This test depends on fleets.status.im being online.
// This dependence must be removed once DNS discovery is implemented
this.timeout(60000); this.timeout(60000);
const id = uuidv4(); const id = uuidv4();
@ -112,7 +108,7 @@ export default function runAll(nodes) {
}); });
messages.forEach((msgs, i) => { messages.forEach((msgs, i) => {
expect(msgs.length).to.eq( expect(msgs.length).to.gte(
nodes.length - 1, nodes.length - 1,
`Unexpected number of messages received by ${hostnames[i]}` `Unexpected number of messages received by ${hostnames[i]}`
); );
@ -132,21 +128,20 @@ export default function runAll(nodes) {
} }
}); });
it("Light Push", async function () { it("Send via Light Push, receive via Relay", async function () {
// This test depends on fleets.status.im being online.
// This dependence must be removed once DNS discovery is implemented
this.timeout(60000); this.timeout(60000);
const id = uuidv4(); const id = uuidv4();
expect(nodes.length).to.eq(3);
const promises = nodes.map(async (node, i) => { const promises = nodes.map(async (node, i) => {
wakus[i] = await Waku.create({ wakus[i] = await Waku.create({
bootstrap: { peers: [node] }, bootstrap: { peers: [node] },
}); });
await wakus[i].waitForRemotePeer([Protocols.LightPush]); await wakus[i].waitForRemotePeer([
Protocols.LightPush,
Protocols.Relay,
]);
console.log(node + ": ready"); console.log(node + ": ready");
}); });
@ -156,11 +151,16 @@ export default function runAll(nodes) {
const contentTopic = `/waku-tests/1/light-push-${id}/utf8`; const contentTopic = `/waku-tests/1/light-push-${id}/utf8`;
const messages = []; const messages = [];
const hostnames = nodes.map((a) => {
const ma = new Multiaddr(a);
return ma.nodeAddress().address;
});
wakus.forEach((waku) => { wakus.forEach((waku, i) => {
messages[i] = [];
waku.relay.addObserver( waku.relay.addObserver(
(message) => { (message) => {
messages.push({ messages[i].push({
msg: message.payloadAsUtf8, msg: message.payloadAsUtf8,
timestamp: message.timestamp, timestamp: message.timestamp,
rcvd: new Date(), rcvd: new Date(),
@ -172,33 +172,46 @@ export default function runAll(nodes) {
const relayPromises = wakus.map(async (waku, i) => { const relayPromises = wakus.map(async (waku, i) => {
const msg = await WakuMessage.fromUtf8String( const msg = await WakuMessage.fromUtf8String(
`sent via ${nodes[i]} - ${id}`, `sent via ${hostnames[i]} - ${id}`,
contentTopic contentTopic
); );
return waku.lightPush.push(msg); return waku.lightPush.push(msg);
}); });
await Promise.all(relayPromises); await Promise.all(relayPromises);
await delay(30000);
console.log(messages); console.log(messages);
messages.forEach((msg) => { messages.forEach((msgs) => {
const diff = msg.rcvd.getTime() - msg.timestamp.getTime(); msgs.forEach((msg) => {
console.log(msg.timestamp, msg.rcvd, diff + "ms"); const diff = msg.rcvd.getTime() - msg.timestamp.getTime();
console.log(msg.timestamp, msg.rcvd, diff + "ms");
});
}); });
expect(messages.length).to.gte(nodes.length); messages.forEach((msgs, i) => {
expect(msgs.length).to.gte(
for (let i = 0; i < wakus.length; i++) { nodes.length - 1,
expect(messages.map((m) => m.msg)).to.contain( `Unexpected number of messages received by ${hostnames[i]}`
`sent via ${nodes[i]} - ${id}`
); );
});
// Checking that message sent by waku[i]
for (let i = 0; i < wakus.length; i++) {
// is received by waku[j]
for (let j = 0; j < wakus.length; j++) {
if (i === j) continue;
expect(messages[j].map((m) => m.msg)).to.contain(
`sent via ${hostnames[i]} - ${id}`,
`Node connected to ${hostnames[j]} did not receive message sent via ${hostnames[i]}`
);
}
} }
}); });
it("Store", async function () { it("Retrieve from Store, sent via Light push", async function () {
// This test depends on fleets.status.im being online.
// This dependence must be removed once DNS discovery is implemented
this.timeout(30000); this.timeout(30000);
expect(nodes.length).to.eq(3); expect(nodes.length).to.eq(3);
@ -210,24 +223,29 @@ export default function runAll(nodes) {
bootstrap: { peers: [node] }, bootstrap: { peers: [node] },
}); });
await wakus[i].waitForRemotePeer([Protocols.Relay]); await wakus[i].waitForRemotePeer([Protocols.Relay, Protocols.Store]);
console.log(node + ": ready"); console.log(node + ": ready");
}); });
await Promise.all(promises); await Promise.all(promises);
// All connected and relay ready // All connected and relay ready
const hostnames = nodes.map((a) => {
const ma = new Multiaddr(a);
return ma.nodeAddress().address;
});
const contentTopic = `/waku-tests/1/store-test-${id}/utf8`; const contentTopic = `/waku-tests/1/store-test-${id}/utf8`;
const relayPromises = wakus.map(async (waku, i) => { const pushPromises = wakus.map(async (waku, i) => {
const msg = await WakuMessage.fromUtf8String( const msg = await WakuMessage.fromUtf8String(
`sent via ${nodes[i]} - ${id}`, `sent via ${nodes[i]} - ${id}`,
contentTopic contentTopic
); );
return waku.relay.send(msg); return waku.lightPush.push(msg);
}); });
await Promise.all(relayPromises); await Promise.all(pushPromises);
await delay(5000); await delay(5000);
const storePromises = wakus.map(async (waku, index) => { const storePromises = wakus.map(async (waku, index) => {
@ -236,7 +254,10 @@ export default function runAll(nodes) {
console.log(index, payloads); console.log(index, payloads);
for (let i = 0; i < wakus.length; i++) { for (let i = 0; i < wakus.length; i++) {
expect(payloads).to.contain(`sent via ${nodes[i]} - ${id}`); expect(payloads).to.contain(
`sent via ${nodes[i]} - ${id}`,
`Store ${hostnames[index]} did not contain message sent via ${hostnames[i]}`
);
} }
}); });