aboutsummaryrefslogtreecommitdiffstats
path: root/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
diff options
context:
space:
mode:
Diffstat (limited to 'k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js')
-rw-r--r--k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js34
1 files changed, 3 insertions, 31 deletions
diff --git a/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js b/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
index 5d54c60f47..cce85ab7cb 100644
--- a/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
+++ b/k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js
@@ -18,9 +18,8 @@
* ============LICENSE_END=========================================================
*/
-import http from 'k6/http';
-import { sleep, fail } from 'k6';
-import { makeCustomSummaryReport, NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js';
+import { makeCustomSummaryReport } from './common/utils.js';
+import { waitForCmHandlesToBeReady } from './common/cmhandle-crud.js';
export const options = {
vus: 1,
@@ -32,35 +31,8 @@ export const options = {
};
export default function () {
- waitForCmHandlesToBeReady(TOTAL_CM_HANDLES);
-}
-
-function waitForCmHandlesToBeReady(totalCmHandles) {
const timeOutInSeconds = 6 * 60;
- const pollingIntervalInSeconds = 10;
- const maxRetries = Math.ceil(timeOutInSeconds / pollingIntervalInSeconds);
- let cmHandlesReady = 0;
- for (let currentTry = 0; currentTry <= maxRetries; currentTry++) {
- sleep(pollingIntervalInSeconds);
- try {
- cmHandlesReady = getNumberOfReadyCmHandles();
- } catch (error) {
- console.error(`Attempt ${currentTry + 1} - Error fetching CM handles: ${error.message}`);
- }
- console.log(`Attempt ${currentTry + 1} - ${cmHandlesReady}/${totalCmHandles} CM handles are READY`);
- if (cmHandlesReady === totalCmHandles) {
- console.log(`All ${totalCmHandles} CM handles are READY`);
- return;
- }
- }
- fail(`Timed out after ${timeoutInSeconds} seconds waiting for ${totalCmHandles} CM handles to be READY`);
-}
-
-function getNumberOfReadyCmHandles() {
- const endpointUrl = `${NCMP_BASE_URL}/cps/api/v2/dataspaces/NCMP-Admin/anchors/ncmp-dmi-registry/node?xpath=/dmi-registry&descendants=all`;
- const jsonData = http.get(endpointUrl).json();
- const cmHandles = jsonData[0]["dmi-reg:dmi-registry"]["cm-handles"];
- return cmHandles.filter(cmhandle => cmhandle['state']['cm-handle-state'] === 'READY').length;
+ waitForCmHandlesToBeReady(timeOutInSeconds);
}
export function handleSummary(data) {