diff --git a/javascript/packages/orchestrator/src/network.ts b/javascript/packages/orchestrator/src/network.ts index 4dbae0c34..fb4ddaa7c 100644 --- a/javascript/packages/orchestrator/src/network.ts +++ b/javascript/packages/orchestrator/src/network.ts @@ -370,7 +370,6 @@ export class Network { replaceWithNetworInfo(placeholder: string): string { return placeholder.replace( - ///{{ZOMBIE:(.*?):(.*?)}}/gi, TOKEN_PLACEHOLDER, (_substring, nodeName, key: keyof NetworkNode) => { const node = this.getNodeByName(nodeName); diff --git a/javascript/packages/orchestrator/src/networkNode.ts b/javascript/packages/orchestrator/src/networkNode.ts index 0818ddda1..9681f2278 100644 --- a/javascript/packages/orchestrator/src/networkNode.ts +++ b/javascript/packages/orchestrator/src/networkNode.ts @@ -40,8 +40,6 @@ export class NetworkNode implements NetworkNodeInterface { userDefinedTypes: any; para?: PARA; parachainId?: number; - lastLogLineCheckedTimestamp?: string; - lastLogLineCheckedIndex?: number; group?: string; constructor( @@ -415,6 +413,8 @@ export class NetworkNode implements NetworkNodeInterface { timeout: number = DEFAULT_INDIVIDUAL_TEST_TIMEOUT, ): Promise { try { + let lastLogLineCheckedTimestamp: string; + let lastLogLineCheckedIndex: number; const re = isGlob ? makeRe(pattern) : new RegExp(pattern, "ig"); if (!re) throw new Error(`Invalid glob pattern: ${pattern} `); const client = getClient(); @@ -425,7 +425,10 @@ export class NetworkNode implements NetworkNodeInterface { const dedupedLogs = this._dedupLogs( logs.split("\n"), client.providerName === "native", + lastLogLineCheckedTimestamp, + lastLogLineCheckedIndex, ); + const index = dedupedLogs.findIndex((line) => { if (client.providerName !== "native") { // remove the extra timestamp @@ -436,11 +439,9 @@ export class NetworkNode implements NetworkNodeInterface { if (index >= 0) { done = true; - this.lastLogLineCheckedTimestamp = dedupedLogs[index]; - this.lastLogLineCheckedIndex = index; - debug( - this.lastLogLineCheckedTimestamp.split(" ").slice(1).join(" "), - ); + lastLogLineCheckedTimestamp = dedupedLogs[index]; + lastLogLineCheckedIndex = index; + debug(lastLogLineCheckedTimestamp.split(" ").slice(1).join(" ")); } else { await new Promise((resolve) => setTimeout(resolve, 1000)); logs = await client.getNodeLogs(this.name, 2, true); @@ -538,12 +539,17 @@ export class NetworkNode implements NetworkNodeInterface { return spanNames; } - // prevent to seach in the same log line twice. - _dedupLogs(logs: string[], useIndex = false): string[] { - if (!this.lastLogLineCheckedTimestamp) return logs; - if (useIndex) return logs.slice(this.lastLogLineCheckedIndex); - - const lastLineTs = this.lastLogLineCheckedTimestamp.split(" ")[0]; + // prevent to search in the same log line twice. + _dedupLogs( + logs: string[], + useIndex = false, + lastLogLineCheckedTimestamp: string, + lastLogLineCheckedIndex: number, + ): string[] { + if (!lastLogLineCheckedTimestamp) return logs; + if (useIndex) return logs.slice(lastLogLineCheckedIndex); + + const lastLineTs = lastLogLineCheckedTimestamp.split(" ")[0]; const index = logs.findIndex((logLine) => { const thisLineTs = logLine.split(" ")[0]; return thisLineTs > lastLineTs; diff --git a/javascript/packages/orchestrator/src/test-runner/assertions.ts b/javascript/packages/orchestrator/src/test-runner/assertions.ts index f46e13801..15449f4d9 100644 --- a/javascript/packages/orchestrator/src/test-runner/assertions.ts +++ b/javascript/packages/orchestrator/src/test-runner/assertions.ts @@ -15,6 +15,7 @@ import { validateRuntimeCode, } from "../jsapi-helpers"; import { Network } from "../network"; +import { NetworkNode } from "../networkNode"; import { FnArgs } from "../types"; const utilCrypto = require("@polkadot/util-crypto"); @@ -127,7 +128,9 @@ const LogMatch = ({ node_name, pattern, match_type, timeout }: FnArgs) => { return async (network: Network) => { const nodes = network.getNodes(node_name!); const results = await Promise.all( - nodes.map((node: any) => node.findPattern(pattern!, isGlob, timeout)), + nodes.map((node: NetworkNode) => + node.findPattern(pattern!, isGlob, timeout), + ), ); const found = results.every(Boolean);