Improve output on error

This commit is contained in:
Franck Royer 2022-04-20 14:14:41 +10:00
parent 06e6ee7f43
commit 34f65b8587
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 42 additions and 14 deletions

View File

@ -24,8 +24,10 @@ export default function runAll(nodes) {
const ma = new Multiaddr(a);
return ma.getPeerId();
});
expect(nodes.length).to.eq(3);
const hostnames = nodes.map((a) => {
const ma = new Multiaddr(a);
return ma.nodeAddress().address;
});
const promises = nodes.map(async (node, i) => {
wakus[i] = await Waku.create({
@ -38,7 +40,10 @@ export default function runAll(nodes) {
});
}).then((peerId) => {
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();
expect(nodes.length).to.eq(3);
const promises = nodes.map(async (node, i) => {
wakus[i] = await Waku.create({
bootstrap: { peers: [node] },
@ -69,11 +72,16 @@ export default function runAll(nodes) {
const contentTopic = `/waku-tests/1/relay-test-${id}/utf8`;
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(
(message) => {
messages.push({
messages[i].push({
msg: message.payloadAsUtf8,
timestamp: message.timestamp,
rcvd: new Date(),
@ -85,7 +93,7 @@ export default function runAll(nodes) {
const relayPromises = wakus.map(async (waku, i) => {
const msg = await WakuMessage.fromUtf8String(
`sent via ${nodes[i]} - ${id}`,
`sent via ${hostnames[i]} - ${id}`,
contentTopic
);
return waku.relay.send(msg);
@ -96,15 +104,31 @@ export default function runAll(nodes) {
console.log(messages);
messages.forEach((msg) => {
const diff = msg.rcvd.getTime() - msg.timestamp.getTime();
console.log(msg.timestamp, msg.rcvd, diff + "ms");
messages.forEach((msgs) => {
msgs.forEach((msg) => {
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++) {
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);
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}`
);
}
});

View File

@ -42,6 +42,7 @@
},
"dependencies": {
"js-waku": "^0.20.0",
"multiaddr": "^10.0.1",
"uuid": "^8.3.2"
}
}

View File

@ -4634,6 +4634,7 @@ __metadata:
eslint-config-prettier: ^8.5.0
js-waku: ^0.20.0
mocha: ^9.2.2
multiaddr: ^10.0.1
npm-run-all: ^4.1.5
prettier: ^2.6.2
uuid: ^8.3.2