Skip to content

Commit

Permalink
Fix count pattern lines (#1811)
Browse files Browse the repository at this point in the history
* fix(runner): countPatternLines, loop until we get the value

* change test to ensure loop

* change test

* fix sleep between checks
  • Loading branch information
pepoviola authored May 27, 2024
1 parent f78b1d5 commit 3b6282b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
31 changes: 23 additions & 8 deletions javascript/packages/orchestrator/src/networkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number> {
try {
Expand All @@ -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<number> => {
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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/smoke/0001-smoke.zndsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b6282b

Please sign in to comment.