Skip to content

Commit

Permalink
Add unique name to each node for identification
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Oct 5, 2023
1 parent 04e34d6 commit 96fdaa8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
10 changes: 8 additions & 2 deletions packages/beacon-node/test/e2e/network/gossipsub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ function runTests(this: Mocha.Suite, {useWorker}: {useWorker: boolean}): void {

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function mockModules(gossipHandlersPartial?: Partial<GossipHandlers>) {
const [netA] = await getNetworkForTest("A", config, {opts: {useWorker}, gossipHandlersPartial});
const [netB, closeB] = await getNetworkForTest("B", config, {opts: {useWorker}, gossipHandlersPartial});
const [netA] = await getNetworkForTest(`gossipsub-${useWorker ? "worker" : "main"}-A`, config, {
opts: {useWorker},
gossipHandlersPartial,
});
const [netB, closeB] = await getNetworkForTest(`gossipsub-${useWorker ? "worker" : "main"}-B`, config, {
opts: {useWorker},
gossipHandlersPartial,
});

afterEachCallbacks.push(async () => {
// await closeA();
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/e2e/network/mdns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe.skip("mdns", function () {

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function createTestNodesAB() {
return Promise.all([createTestNode("A"), createTestNode("B")]);
return Promise.all([createTestNode("mdns-A"), createTestNode("mdns-B")]);
}

it("should connect two peers on a LAN", async function () {
Expand Down
26 changes: 16 additions & 10 deletions packages/beacon-node/test/e2e/network/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,44 @@ function runTests(this: Mocha.Suite, {useWorker}: {useWorker: boolean}): void {

const afterEachCallbacks: (() => Promise<void> | void)[] = [];
afterEach(async () => {
await Promise.all(afterEachCallbacks.map((cb) => cb()));
afterEachCallbacks.splice(0, afterEachCallbacks.length);
while (afterEachCallbacks.length > 0) {
const callback = afterEachCallbacks.pop();
if (callback) await callback();
}
});

let controller: AbortController;
beforeEach(() => (controller = new AbortController()));
afterEach(() => controller.abort());
afterEach(() => {
controller.abort();
sinon.restore();
});

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function createTestNode(nodeName: string) {
const [network, closeAll] = await getNetworkForTest(nodeName, config, {opts: {useWorker}});

afterEachCallbacks.push(async () => {
await closeAll();
sinon.restore();
});

return network;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async function createTestNodesAB() {
return Promise.all([createTestNode("A"), createTestNode("B")]);
async function createTestNodesAB(): Promise<[Network, Network]> {
return Promise.all([
createTestNode(`network-${useWorker ? "worker" : "main"}-A`),
createTestNode(`network-${useWorker ? "worker" : "main"}-A`),
]);
}

it("Disconnect peer", async () => {
const network = await createTestNode("A");
const network = await createTestNode(`network-${useWorker ? "worker" : "main"}-DP`);
await network.disconnectPeer(getValidPeerId().toString());
});

it("return getNetworkIdentity", async () => {
const network = await createTestNode("A");
const network = await createTestNode(`network-${useWorker ? "worker" : "main"}-NI`);
const networkIdentity = await network.getNetworkIdentity();
expect(networkIdentity.peerId).equals(network.peerId.toString());
});
Expand Down Expand Up @@ -124,7 +130,7 @@ function runTests(this: Mocha.Suite, {useWorker}: {useWorker: boolean}): void {
});

it("Should subscribe to gossip core topics on demand", async () => {
const netA = await createTestNode("A");
const netA = await createTestNode(`network-${useWorker ? "worker" : "main"}-CT`);

expect(await getTopics(netA)).deep.equals([]);

Expand Down
10 changes: 8 additions & 2 deletions packages/beacon-node/test/e2e/network/reqresp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ function runTests(this: Mocha.Suite, {useWorker}: {useWorker: boolean}): void {
getReqRespHandler?: GetReqRespHandlerFn,
opts?: ReqRespBeaconNodeOpts
): Promise<[Network, Network, PeerIdStr, PeerIdStr]> {
const [netA, closeA] = await getNetworkForTest("A", config, {getReqRespHandler, opts: {...opts, useWorker}});
const [netB, closeB] = await getNetworkForTest("B", config, {getReqRespHandler, opts: {...opts, useWorker}});
const [netA, closeA] = await getNetworkForTest(`reqresp-${useWorker ? "worker" : "main"}-A`, config, {
getReqRespHandler,
opts: {...opts, useWorker},
});
const [netB, closeB] = await getNetworkForTest(`reqresp-${useWorker ? "worker" : "main"}-B`, config, {
getReqRespHandler,
opts: {...opts, useWorker},
});

afterEachCallbacks.push(async () => {
await closeA();
Expand Down

0 comments on commit 96fdaa8

Please sign in to comment.