n8n/packages/@n8n/benchmark/src/testExecution/k6Executor.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
656 B
TypeScript
Raw Normal View History

import { $ } from 'zx';
import { Scenario } from '@/types/scenario';
/**
* Executes test scenarios using k6
*/
export class K6Executor {
constructor(
private readonly k6ExecutablePath: string,
private readonly n8nApiBaseUrl: string,
) {}
async executeTestScenario(scenario: Scenario) {
// For 1 min with 5 virtual users
const stage = '1m:5';
const processPromise = $({
cwd: scenario.scenarioDirPath,
env: {
API_BASE_URL: this.n8nApiBaseUrl,
},
})`${this.k6ExecutablePath} run --quiet --stage ${stage} ${scenario.scriptPath}`;
for await (const chunk of processPromise.stdout) {
console.log(chunk.toString());
}
}
}