Improve output on error
This commit is contained in:
parent
06e6ee7f43
commit
34f65b8587
54
index.js
54
index.js
|
@ -24,8 +24,10 @@ export default function runAll(nodes) {
|
||||||
const ma = new Multiaddr(a);
|
const ma = new Multiaddr(a);
|
||||||
return ma.getPeerId();
|
return ma.getPeerId();
|
||||||
});
|
});
|
||||||
|
const hostnames = nodes.map((a) => {
|
||||||
expect(nodes.length).to.eq(3);
|
const ma = new Multiaddr(a);
|
||||||
|
return ma.nodeAddress().address;
|
||||||
|
});
|
||||||
|
|
||||||
const promises = nodes.map(async (node, i) => {
|
const promises = nodes.map(async (node, i) => {
|
||||||
wakus[i] = await Waku.create({
|
wakus[i] = await Waku.create({
|
||||||
|
@ -38,7 +40,10 @@ export default function runAll(nodes) {
|
||||||
});
|
});
|
||||||
}).then((peerId) => {
|
}).then((peerId) => {
|
||||||
console.log("connected", peerId.toB58String());
|
console.log("connected", peerId.toB58String());
|
||||||
expect(peerId.toB58String()).to.eq(peerIds[i]);
|
expect(peerId.toB58String()).to.eq(
|
||||||
|
peerIds[i],
|
||||||
|
`Could not connect to ${hostnames[i]}`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,8 +57,6 @@ export default function runAll(nodes) {
|
||||||
|
|
||||||
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] },
|
||||||
|
@ -69,11 +72,16 @@ export default function runAll(nodes) {
|
||||||
const contentTopic = `/waku-tests/1/relay-test-${id}/utf8`;
|
const contentTopic = `/waku-tests/1/relay-test-${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(),
|
||||||
|
@ -85,7 +93,7 @@ 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.relay.send(msg);
|
return waku.relay.send(msg);
|
||||||
|
@ -96,15 +104,31 @@ export default function runAll(nodes) {
|
||||||
|
|
||||||
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.eq(
|
||||||
|
nodes.length - 1,
|
||||||
|
`Unexpected number of messages received by ${hostnames[i]}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Checking that message sent by waku[i]
|
||||||
for (let i = 0; i < wakus.length; i++) {
|
for (let i = 0; i < wakus.length; i++) {
|
||||||
expect(messages.map((m) => m.msg)).to.contain(`sent via ${nodes[i]} - ${id}`);
|
// 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]}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,7 +190,9 @@ export default function runAll(nodes) {
|
||||||
expect(messages.length).to.gte(nodes.length);
|
expect(messages.length).to.gte(nodes.length);
|
||||||
|
|
||||||
for (let i = 0; i < wakus.length; i++) {
|
for (let i = 0; i < wakus.length; i++) {
|
||||||
expect(messages.map((m) => m.msg)).to.contain(`sent via ${nodes[i]} - ${id}`);
|
expect(messages.map((m) => m.msg)).to.contain(
|
||||||
|
`sent via ${nodes[i]} - ${id}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-waku": "^0.20.0",
|
"js-waku": "^0.20.0",
|
||||||
|
"multiaddr": "^10.0.1",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue