Skip to content

Commit

Permalink
WIP 3
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Oct 27, 2023
1 parent 52839eb commit 503aa2c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions test/scripts/zombienetRestart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ yargs(hideBin(process.argv))
});

process.on("SIGINT", () => {
console.log('zombienetRestart: got SIGINT');
child.kill("SIGINT");
});
}, argv["wait-ms"]);
Expand Down
58 changes: 55 additions & 3 deletions test/suites/keep-db/test_restart_keep_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getKeyringNimbusIdHex } from "../../util/keys";
import { getHeaderFromRelay } from "../../util/relayInterface";
import { exec } from "child_process";
import { ExecaChildProcess, execa } from "execa";
import fs from "fs/promises";

describeSuite({
id: "ZK01",
Expand Down Expand Up @@ -42,8 +43,14 @@ describeSuite({
}, 120000);

afterAll(async () => {
// TODO: this doesn't seem to run after the tests fail?
// Or maybe, this is only able to kill the zombienetRestart.ts process, not the tanssi-node
// once it has been started?
for (const h of restartedHandles) {
h.kill();
console.log('afterAll: killing ', h.pid, ' (exit code? ', h.exitCode, ')');
h.kill('SIGINT');
await sleep(1000);
console.log('afterAll: killed ', h.pid, ' (exit code? ', h.exitCode, ')');
}
});

Expand Down Expand Up @@ -171,7 +178,16 @@ describeSuite({

await sleep(5000);

// TODO: Check db has not been deleted
// Check db has not been deleted
const dbPath01 =
getTmpZombiePath() +
`/Collator2000-01/data/containers/chains/simple_container_2000/db/full-container-2000`;
const dbPath02 =
getTmpZombiePath() +
`/Collator2000-02/data/containers/chains/simple_container_2000/db/full-container-2000`;

expect(await directoryExists(dbPath01)).to.be.true;
expect(await directoryExists(dbPath02)).to.be.true;

// TODO: Check both collators are still producing blocks
},
Expand All @@ -193,12 +209,26 @@ describeSuite({
await signAndSendAndInclude(paraApi.tx.sudo.sudo(tx), alice);
await waitSessions(context, paraApi, 2);

// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
await context.waitBlock(3, "Tanssi");

// Check that pending para ids removes 2000
const registered = await paraApi.query.registrar.registeredParaIds();
// TODO: fix once we have types
expect(registered.toJSON().includes(2000)).to.be.false;

// TODO: check Collator2000-01 db path exists, and Collator2000-02 has deleted it
// Check Collator2000-01 db path exists, and Collator2000-02 has deleted it
const dbPath01 =
getTmpZombiePath() +
`/Collator2000-01/data/containers/chains/simple_container_2000/db/full-container-2000`;
const dbPath02 =
getTmpZombiePath() +
`/Collator2000-02/data/containers/chains/simple_container_2000/db/full-container-2000`;

expect(await directoryExists(dbPath01)).to.be.true;
expect(await directoryExists(dbPath02)).to.be.false;

},
});
},
Expand Down Expand Up @@ -247,3 +277,25 @@ const execPromisify = (command: string) => {
});
});
};

async function directoryExists(directoryPath) {
try {
await fs.access(directoryPath, fs.constants.F_OK);
return true;
} catch (err) {
return false;
}
}

/// Returns the /tmp/zombie-52234... path
function getTmpZombiePath() {
const logFilePath = process.env.MOON_MONITORED_NODE;

if (logFilePath) {
const lastIndex = logFilePath.lastIndexOf("/");
return lastIndex !== -1 ? logFilePath.substring(0, lastIndex) : null;
}

// Return null if the environment variable is not set
return null;
}
4 changes: 4 additions & 0 deletions test/suites/metrics/test_metrics_stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describeSuite({
await signAndSendAndInclude(paraApi.tx.sudo.sudo(tx), alice);
await waitSessions(context, paraApi, 2);

// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
await context.waitBlock(3, "Tanssi");

// Check that pending para ids removes 2000
const registered = await paraApi.query.registrar.registeredParaIds();
// TODO: fix once we have types
Expand Down
15 changes: 0 additions & 15 deletions test/suites/warp-sync/test_warp_sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ describeSuite({
// TODO: fix once we have types
const genesisData2000 = await paraApi.query.registrar.paraGenesisData(2000);
expect(genesisData2000.toJSON().properties.isEthereum).to.be.false;

// Restart the process in the current terminal with its original environment variables and cwd
const child = spawn(command, args, {
stdio: "inherit",
cwd: cwd,
env: Object.fromEntries(envVariables.map((e) => e.split("=", 2))),
});

process.on("SIGINT", () => {
child.kill("SIGINT");
});

process.on("exit", () => {
// Kill process
});
},
});

Expand Down

0 comments on commit 503aa2c

Please sign in to comment.