Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix resolving of k6 executable (no-changelog) #10511

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/@n8n/benchmark/src/testExecution/k6Executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $ } from 'zx';
import { $, which } from 'zx';
import { Scenario } from '@/types/scenario';

/**
Expand All @@ -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<string> {
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;
}
}
Loading