mirror of https://github.com/waku-org/js-waku.git
Kill nim-waku & js-libp2p nodes after tests
This commit is contained in:
parent
13e941513d
commit
090b064c84
|
@ -32,6 +32,9 @@ describe('Waku', () => {
|
||||||
const jsPeers = waku.libp2p.peerStore.peers;
|
const jsPeers = waku.libp2p.peerStore.peers;
|
||||||
|
|
||||||
expect(jsPeers.has(nimPeerId.toB58String())).toBeTruthy();
|
expect(jsPeers.has(nimPeerId.toB58String())).toBeTruthy();
|
||||||
|
|
||||||
|
nimWaku.stop();
|
||||||
|
await waku.stop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,4 +27,8 @@ export default class Waku {
|
||||||
|
|
||||||
return new Waku(libp2p, new WakuRelay(libp2p.pubsub));
|
return new Waku(libp2p, new WakuRelay(libp2p.pubsub));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async stop() {
|
||||||
|
await this.libp2p.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ describe('Waku Relay', () => {
|
||||||
const node1Received = await promise;
|
const node1Received = await promise;
|
||||||
|
|
||||||
expect(node1Received.isEqualTo(message)).toBeTruthy();
|
expect(node1Received.isEqualTo(message)).toBeTruthy();
|
||||||
|
|
||||||
|
await Promise.all([waku1.stop(), waku2.stop()]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Registers waku relay protocol', async () => {
|
test('Registers waku relay protocol', async () => {
|
||||||
|
@ -45,6 +47,8 @@ describe('Waku Relay', () => {
|
||||||
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
||||||
|
|
||||||
expect(protocols.findIndex((value) => value == CODEC)).toBeTruthy();
|
expect(protocols.findIndex((value) => value == CODEC)).toBeTruthy();
|
||||||
|
|
||||||
|
await waku.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Does not register any sub protocol', async () => {
|
test('Does not register any sub protocol', async () => {
|
||||||
|
@ -52,22 +56,33 @@ describe('Waku Relay', () => {
|
||||||
|
|
||||||
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
||||||
expect(protocols.findIndex((value) => value.match(/sub/))).toBeTruthy();
|
expect(protocols.findIndex((value) => value.match(/sub/))).toBeTruthy();
|
||||||
|
|
||||||
|
await waku.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Interop: Nim', () => {
|
describe('Interop: Nim', () => {
|
||||||
test('nim subscribes to js', async () => {
|
let waku: Waku;
|
||||||
const waku = await Waku.create();
|
let nimWaku: NimWaku;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
waku = await Waku.create();
|
||||||
|
|
||||||
const peerId = waku.libp2p.peerId.toB58String();
|
const peerId = waku.libp2p.peerId.toB58String();
|
||||||
|
|
||||||
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
|
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
|
||||||
addr.toString().match(/127\.0\.0\.1/)
|
addr.toString().match(/127\.0\.0\.1/)
|
||||||
);
|
);
|
||||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
||||||
|
|
||||||
const nimWaku = new NimWaku(expect.getState().currentTestName);
|
nimWaku = new NimWaku(expect.getState().currentTestName);
|
||||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
nimWaku ? nimWaku.stop() : null;
|
||||||
|
waku ? await waku.stop() : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('nim subscribes to js', async () => {
|
||||||
const nimPeerId = await nimWaku.getPeerId();
|
const nimPeerId = await nimWaku.getPeerId();
|
||||||
const subscribers = waku.libp2p.pubsub.getSubscribers(TOPIC);
|
const subscribers = waku.libp2p.pubsub.getSubscribers(TOPIC);
|
||||||
|
|
||||||
|
@ -76,22 +91,11 @@ describe('Waku Relay', () => {
|
||||||
|
|
||||||
test('Js publishes to nim', async () => {
|
test('Js publishes to nim', async () => {
|
||||||
const message = Message.fromUtf8String('This is a message');
|
const message = Message.fromUtf8String('This is a message');
|
||||||
const waku = await Waku.create();
|
|
||||||
|
|
||||||
// TODO: nim-waku does follow the `StrictNoSign` policy hence we need to change
|
// TODO: nim-waku does follow the `StrictNoSign` policy hence we need to change
|
||||||
// it for nim-waku to process our messages. Can be removed once
|
// it for nim-waku to process our messages. Can be removed once
|
||||||
// https://github.com/status-im/nim-waku/issues/422 is fixed
|
// https://github.com/status-im/nim-waku/issues/422 is fixed
|
||||||
waku.libp2p.pubsub.globalSignaturePolicy = 'StrictSign';
|
waku.libp2p.pubsub.globalSignaturePolicy = 'StrictSign';
|
||||||
|
|
||||||
const peerId = waku.libp2p.peerId.toB58String();
|
|
||||||
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
|
|
||||||
addr.toString().match(/127\.0\.0\.1/)
|
|
||||||
);
|
|
||||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
|
||||||
|
|
||||||
const nimWaku = new NimWaku(expect.getState().currentTestName);
|
|
||||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
|
||||||
|
|
||||||
await patchPeerStore(nimWaku, waku.libp2p);
|
await patchPeerStore(nimWaku, waku.libp2p);
|
||||||
|
|
||||||
await waku.relay.publish(message);
|
await waku.relay.publish(message);
|
||||||
|
@ -109,16 +113,6 @@ describe('Waku Relay', () => {
|
||||||
|
|
||||||
test('Nim publishes to js', async () => {
|
test('Nim publishes to js', async () => {
|
||||||
const message = Message.fromUtf8String('Here is another message.');
|
const message = Message.fromUtf8String('Here is another message.');
|
||||||
const waku = await Waku.create();
|
|
||||||
|
|
||||||
const peerId = waku.libp2p.peerId.toB58String();
|
|
||||||
const localMultiaddr = waku.libp2p.multiaddrs.find((addr) =>
|
|
||||||
addr.toString().match(/127\.0\.0\.1/)
|
|
||||||
);
|
|
||||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
|
||||||
|
|
||||||
const nimWaku = new NimWaku(expect.getState().currentTestName);
|
|
||||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
|
||||||
|
|
||||||
await patchPeerStore(nimWaku, waku.libp2p);
|
await patchPeerStore(nimWaku, waku.libp2p);
|
||||||
|
|
||||||
|
|
|
@ -74,13 +74,13 @@ export class NimWaku {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.process.on('exit', (signal) => {
|
|
||||||
console.log(`ERROR: nim-waku node stopped: ${signal}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.waitForLog('RPC Server started');
|
await this.waitForLog('RPC Server started');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public stop() {
|
||||||
|
this.process ? this.process.kill('SIGINT') : null;
|
||||||
|
}
|
||||||
|
|
||||||
async waitForLog(msg: string) {
|
async waitForLog(msg: string) {
|
||||||
return waitForLine(this.logPath, msg);
|
return waitForLine(this.logPath, msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue