diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-06-10 21:32:12 +0100 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-06-14 16:17:13 +0100 |
commit | f66694a076be41d83693423dec818493bcf66715 (patch) | |
tree | 452e1d54ea3a8a9c288c69491a5498118b5f57a0 /k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js | |
parent | 35e0df312cbb2fd0a3740805636338713836b5e1 (diff) |
[k6] Refactoring k6 tests (#1)
This commit moves all common request logic into a common folder.
It is needed to avoid duplication before adding JVM warmup phase.
- move registration-related code into common folder
- move passthrough operations into common folder
Issue-ID: CPS-2208
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Ia9ebf61d21044b43063bde153f9c526e67d607c8
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.js | 34 |
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) { |