diff --git a/packages/@n8n/benchmark/src/testExecution/k6Executor.ts b/packages/@n8n/benchmark/src/testExecution/k6Executor.ts index 903d06ca74..49386993a5 100644 --- a/packages/@n8n/benchmark/src/testExecution/k6Executor.ts +++ b/packages/@n8n/benchmark/src/testExecution/k6Executor.ts @@ -1,4 +1,4 @@ -import { $ } from 'zx'; +import { $, which } from 'zx'; import { Scenario } from '@/types/scenario'; /** @@ -14,15 +14,31 @@ export class K6Executor { // For 1 min with 5 virtual users const stage = '1m:5'; + const k6ExecutablePath = await this.resolveK6ExecutablePath(); + const processPromise = $({ cwd: scenario.scenarioDirPath, env: { API_BASE_URL: this.n8nApiBaseUrl, }, - })`${this.k6ExecutablePath} run --quiet --stage ${stage} ${scenario.scriptPath}`; + })`${k6ExecutablePath} run --quiet --stage ${stage} ${scenario.scriptPath}`; for await (const chunk of processPromise.stdout) { console.log(chunk.toString()); } } + + /** + * @returns Resolved path to the k6 executable + */ + private async resolveK6ExecutablePath(): Promise { + const k6ExecutablePath = await which(this.k6ExecutablePath, { nothrow: true }); + if (!k6ExecutablePath) { + throw new Error( + 'Could not find k6 executable based on your `PATH`. Please ensure k6 is available in your system and add it to your `PATH` or specify the path to the k6 executable using the `K6_PATH` environment variable.', + ); + } + + return k6ExecutablePath; + } }