|
16 | 16 | import http from 'k6/http'; |
17 | 17 | import {check, sleep} from 'k6'; |
18 | 18 | import {Trend, Counter} from 'k6/metrics'; |
| 19 | +import { test } from 'k6/execution'; |
19 | 20 | import {htmlReport} from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js"; |
20 | 21 | import {textSummary} from "https://jslib.k6.io/k6-summary/0.0.1/index.js"; |
21 | 22 |
|
@@ -90,8 +91,23 @@ export function setup() { |
90 | 91 |
|
91 | 92 | export default function () { |
92 | 93 | 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 |
95 | 111 | return; |
96 | 112 | } |
97 | 113 | } |
@@ -457,7 +473,7 @@ function getDevWorkspacesFromApiServer() { |
457 | 473 | } |
458 | 474 |
|
459 | 475 | const body = JSON.parse(res.body); |
460 | | - return body.items.map((dw) => dw.metadata.name); |
| 476 | + return body.items; |
461 | 477 | } |
462 | 478 |
|
463 | 479 | function generateDevWorkspaceToCreate(vuId, iteration, namespace) { |
|
0 commit comments