diff --git a/javascript/packages/orchestrator/src/networkNode.ts b/javascript/packages/orchestrator/src/networkNode.ts index 1009711f8..38156acb9 100644 --- a/javascript/packages/orchestrator/src/networkNode.ts +++ b/javascript/packages/orchestrator/src/networkNode.ts @@ -433,6 +433,8 @@ export class NetworkNode implements NetworkNodeInterface { async countPatternLines( pattern: string, isGlob: boolean, + comparator: string, + desiredMetricValue: number, timeout: number = DEFAULT_INDIVIDUAL_TEST_TIMEOUT, ): Promise { try { @@ -441,18 +443,31 @@ export class NetworkNode implements NetworkNodeInterface { if (!re) throw new Error(`Invalid glob pattern: ${pattern} `); const client = getClient(); const getValue = async (): Promise => { - await new Promise((resolve) => setTimeout(resolve, timeout * 1000)); - const logs = await client.getNodeLogs(this.name, undefined, true); + let done = false; + + while (!done) { + let value = 0; + const logs = await client.getNodeLogs(this.name, undefined, true); - for (let line of logs.split("\n")) { - if (client.providerName !== "native") { - // remove the extra timestamp - line = line.split(" ").slice(1).join(" "); + for (let line of logs.split("\n")) { + if (client.providerName !== "native") { + // remove the extra timestamp + line = line.split(" ").slice(1).join(" "); + } + if (re.test(line)) { + value += 1; + } } - if (re.test(line)) { - total_count += 1; + + // save to return + total_count = value; + if (compare(comparator, value, desiredMetricValue)) { + done = true; + } else { + await new Promise((resolve) => setTimeout(resolve, 1000)); } } + return total_count; }; diff --git a/javascript/packages/orchestrator/src/test-runner/assertions.ts b/javascript/packages/orchestrator/src/test-runner/assertions.ts index 6a7908936..21ca9c357 100644 --- a/javascript/packages/orchestrator/src/test-runner/assertions.ts +++ b/javascript/packages/orchestrator/src/test-runner/assertions.ts @@ -189,7 +189,13 @@ const CountLogMatch = ({ const nodes = network.getNodes(node_name!); const results = await Promise.all( nodes.map((node: any) => - node.countPatternLines(pattern!, isGlob, timeout), + node.countPatternLines( + pattern!, + isGlob, + toChaiComparator(op!), + target_value, + timeout, + ), ), ); diff --git a/tests/smoke/0001-smoke.zndsl b/tests/smoke/0001-smoke.zndsl index a973e1500..b53c6d2cd 100644 --- a/tests/smoke/0001-smoke.zndsl +++ b/tests/smoke/0001-smoke.zndsl @@ -17,7 +17,7 @@ alice: parachain 100 block height is at least 3 within 250 seconds alice: log line contains "Imported #2" within 20 seconds alice: log line matches glob "*rted #2*" within 20 seconds alice: log line matches "Imported #[0-9]+" within 10 seconds -alice: count of log lines containing "imported" is at least 4 within 10 seconds +alice: count of log lines containing "imported" is at least 30 within 300 seconds # Events assertions