Skip to content

Commit

Permalink
Some polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Mar 17, 2023
1 parent e896fde commit ec90579
Showing 1 changed file with 118 additions and 113 deletions.
231 changes: 118 additions & 113 deletions javascript/packages/orchestrator/src/test-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,106 @@ export interface BackchannelMap {
[propertyName: string]: any;
}

function findNetwork(
networks: Network[],
nodeOrGroupName?: string,
): Network | undefined {
// Find the first network that contains the node and run the test on it.
if (!nodeOrGroupName) {
return undefined;
}

return networks.find((network) => {
try {
network.getNodes(nodeOrGroupName);
return true;
} catch {}
});
}

async function stopNetwork(
network: Network,
name: string,
inCI: boolean,
failed: boolean,
) {
switch (network.client.providerName) {
case "kubernetes":
if (inCI && failed) {
// keep pods running for 30 mins.
console.log(
`\t${decorators.red(
"One or more test failed, we will keep the namespace up for 30 more minutes",
)}`,
);
await network.upsertCronJob(30);
break;
}
default:
console.log(`\t ${decorators.green(`Deleting network ${name}`)}`);
await network.stop();
break;
}
}

function showNetworkLogsLocation(
network: Network,
logsPath: string,
inCI: boolean,
) {
console.log(
`\n\t${decorators.magenta(
"📓 To see the full logs of the nodes please go to:",
)}`,
);
switch (network.client.providerName) {
case "kubernetes":
if (inCI) {
// show links to grafana and also we need to move the logs to artifacts
const networkEndTime = new Date().getTime();
for (const node of network.relay) {
const loki_url = getLokiUrl(
network.namespace,
node.name,
network.networkStartTime!,
networkEndTime,
);
console.log(
`\t${decorators.magenta(node.name)}: ${decorators.green(loki_url)}`,
);
}

for (const [paraId, parachain] of Object.entries(network.paras)) {
console.log(`\n\tParaId: ${decorators.magenta(paraId)}`);
for (const node of parachain?.nodes) {
const loki_url = getLokiUrl(
network.namespace,
node.name,
network.networkStartTime!,
networkEndTime,
);
console.log(
`\t\t${decorators.magenta(node.name)}: ${decorators.green(
loki_url,
)}`,
);
}
}

// logs are also collected as artifacts
console.log(
`\n\n\t ${decorators.yellow(
"📓 Logs are also available in the artifacts' pipeline in gitlab",
)}`,
);
break;
}
default:
console.log(`\n\t${decorators.magenta(logsPath)}`);
break;
}
}

export async function run(
configBasePath: string,
testName: string,
Expand Down Expand Up @@ -106,7 +206,9 @@ export async function run(

let network: Network;
if (!runningNetworkSpecPath) {
console.log(`\t Launching network... this can take a while.`);
console.log(
`\t Launching network ${testDef.networks[networkConfigIdx]} ... this can take a while.`,
);
network = await start(creds!, networkConfig, {
spawnConcurrency: concurrency,
inCI,
Expand Down Expand Up @@ -145,110 +247,22 @@ export async function run(
});

suite.afterAll("teardown", async function () {
for (let network of networks) {
this.timeout(180 * 1000);
if (network && !network.wasRunning) {
const logsPath = await network.dumpLogs(false);
const tests = this.test?.parent?.tests;
this.timeout(180 * 1000);
const tests = this.test?.parent?.tests;

if (tests) {
const failed = tests.filter((test) => {
return test.state !== "passed";
});
if (failed.length) {
console.log(
`\n\n\t${decorators.red(
"❌ One or more of your test failed...",
)}`,
);

switch (network.client.providerName) {
case "podman":
case "native":
console.log(`\n\t ${decorators.green("Deleting network")}`);
await network.stop();
break;
case "kubernetes":
if (inCI) {
// keep pods running for 30 mins.
console.log(
`\n\t${decorators.red(
"One or more test failed, we will keep the namespace up for 30 more minutes",
)}`,
);
await network.upsertCronJob(30);
} else {
console.log(`\n\t ${decorators.green("Deleting network")}`);
await network.stop();
}
break;
}
} else {
// All test passed, just remove the network
console.log(`\n\t ${decorators.green("Deleting network")}`);
await network.stop();
}
const failed = tests?.some((test) => test.state !== "passed") ?? false;
if (failed) {
console.log(
`\n\n\t${decorators.red("❌ One or more of your tests failed...")}`,
);
}

// show logs
console.log(
`\n\n\t${decorators.magenta(
"📓 To see the full logs of the nodes please go to:",
)}`,
);
switch (network.client.providerName) {
case "podman":
case "native":
console.log(`\n\t${decorators.magenta(logsPath)}`);
break;
case "kubernetes":
if (inCI) {
// show links to grafana and also we need to move the logs to artifacts
const networkEndtime = new Date().getTime();
for (const node of network.relay) {
const loki_url = getLokiUrl(
network.namespace,
node.name,
network.networkStartTime!,
networkEndtime,
);
console.log(
`\t${decorators.magenta(node.name)}: ${decorators.green(
loki_url,
)}`,
);
}

for (const [paraId, parachain] of Object.entries(
network.paras,
)) {
console.log(`\n\tParaId: ${decorators.magenta(paraId)}`);
for (const node of parachain?.nodes) {
const loki_url = getLokiUrl(
network.namespace,
node.name,
network.networkStartTime!,
networkEndtime,
);
console.log(
`\t\t${decorators.magenta(node.name)}: ${decorators.green(
loki_url,
)}`,
);
}
}

// logs are also collaected as artifacts
console.log(
`\n\n\t ${decorators.yellow(
"📓 Logs are also available in the artifacts' pipeline in gitlab",
)}`,
);
} else {
console.log(`\n\t${decorators.magenta(logsPath)}`);
}
break;
}
}
for (let [networkIdx, network] of networks.entries()) {
if (network && !network.wasRunning) {
console.log("\n");
const logsPath = await network.dumpLogs(false);
await stopNetwork(network, testDef.networks[networkIdx], inCI, failed);
showNetworkLogsLocation(network, logsPath, inCI);
}
}
return;
Expand All @@ -270,16 +284,7 @@ export async function run(
let testFn = generator(assertion.parsed.args);
const test = new Test(assertion.original_line, async () => {
// Find the first network that contains the node and run the test on it.
let nodeName = assertion.parsed.args.node_name;
let network: Network | undefined;
if (nodeName) {
network = networks.find((network) => {
try {
network.getNodes(nodeName!);
return true;
} catch {}
});
}
let network = findNetwork(networks, assertion.parsed.args.node_name);

setClient(network?.client);
await testFn(network, backchannelMap, configBasePath);
Expand Down

0 comments on commit ec90579

Please sign in to comment.