Skip to content

Commit b36af07

Browse files
committed
fix : add logic to abort test execution when max devworkspaces target is reached
Instead of returning from each VU iteration after checking number of currently running DevWorkspaces, abort the test execution to save time and reduce load on K8s apiserver. Signed-off-by: Rohan Kumar <[email protected]>
1 parent 81d2ec4 commit b36af07

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/load/devworkspace_load_test.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import http from 'k6/http';
1717
import {check, sleep} from 'k6';
1818
import {Trend, Counter} from 'k6/metrics';
19+
import { test } from 'k6/execution';
1920
import {htmlReport} from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
2021
import {textSummary} from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
2122

@@ -90,8 +91,23 @@ export function setup() {
9091

9192
export default function () {
9293
if (maxDevWorkspaces > 0) {
93-
const totalDevWorkspaces = getDevWorkspacesFromApiServer().length;
94-
if (totalDevWorkspaces > maxDevWorkspaces) {
94+
const devWorkspaces = getDevWorkspacesFromApiServer();
95+
const totalDevWorkspaces = devWorkspaces.length;
96+
97+
const runningDevWorkspaces = devWorkspaces.filter(
98+
(dw) => dw.status && dw.status.phase === 'Running'
99+
).length;
100+
const startingDevWorkspaces = devWorkspaces.filter(
101+
(dw) => dw.status && dw.status.phase === 'Starting'
102+
).length;
103+
104+
if (startingDevWorkspaces === 0 && runningDevWorkspaces >= maxDevWorkspaces) {
105+
test.abort(
106+
'Max concurrent DevWorkspaces target achieved (no Starting workspaces), stopping test gracefully',
107+
{ abortOnFail: false }
108+
);
109+
} else if (totalDevWorkspaces >= maxDevWorkspaces) {
110+
// stop further creation, but don’t abort the test
95111
return;
96112
}
97113
}
@@ -457,7 +473,7 @@ function getDevWorkspacesFromApiServer() {
457473
}
458474

459475
const body = JSON.parse(res.body);
460-
return body.items.map((dw) => dw.metadata.name);
476+
return body.items;
461477
}
462478

463479
function generateDevWorkspaceToCreate(vuId, iteration, namespace) {

0 commit comments

Comments
 (0)