aboutsummaryrefslogtreecommitdiffstats
path: root/k6-tests/ncmp/common/cmhandle-crud.js
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-06-28 13:43:35 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-07-05 12:32:58 +0100
commit4e9f68c7e11b05e82e53b3149caf8443026b5ca0 (patch)
treee80ceaed463948edb0fdb45caf88737e20d0b1d6 /k6-tests/ncmp/common/cmhandle-crud.js
parentc1c26ec8a97ce7de7d976665ae0c147fbf9ad80d (diff)
[k6] Measure CM-handle (de)registration in CM-handles/sec
As per characteristics requirements document: - measure registration in CM-handles/second - measure deregistration in CM-handles/second - summary table includes test case number, description, units of measurement, actual value and limit. Issue-ID: CPS-2269 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I838004da1c230ab722f49c2adacf34e730d7ac79
Diffstat (limited to 'k6-tests/ncmp/common/cmhandle-crud.js')
-rw-r--r--k6-tests/ncmp/common/cmhandle-crud.js75
1 files changed, 36 insertions, 39 deletions
diff --git a/k6-tests/ncmp/common/cmhandle-crud.js b/k6-tests/ncmp/common/cmhandle-crud.js
index 0c3e116a19..6d5aff7fca 100644
--- a/k6-tests/ncmp/common/cmhandle-crud.js
+++ b/k6-tests/ncmp/common/cmhandle-crud.js
@@ -19,10 +19,28 @@
*/
import http from 'k6/http';
-import { check, sleep, fail } from 'k6';
-import { NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES } from './utils.js';
+import { check, sleep } from 'k6';
+import { NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES, REGISTRATION_BATCH_SIZE, CONTENT_TYPE_JSON_PARAM, makeBatchOfCmHandleIds } from './utils.js';
+import { executeCmHandleIdSearch } from './search-base.js';
-export function createCmHandles(cmHandleIds) {
+export function registerAllCmHandles() {
+ forEachBatchOfCmHandles(createCmHandles);
+ waitForAllCmHandlesToBeReady();
+}
+
+export function deregisterAllCmHandles() {
+ forEachBatchOfCmHandles(deleteCmHandles);
+}
+
+function forEachBatchOfCmHandles(functionToExecute) {
+ const TOTAL_BATCHES = Math.ceil(TOTAL_CM_HANDLES / REGISTRATION_BATCH_SIZE);
+ for (let batchNumber = 0; batchNumber < TOTAL_BATCHES; batchNumber++) {
+ const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(REGISTRATION_BATCH_SIZE, batchNumber);
+ functionToExecute(nextBatchOfCmHandleIds);
+ }
+}
+
+function createCmHandles(cmHandleIds) {
const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`;
const payload = {
"dmiPlugin": DMI_PLUGIN_URL,
@@ -36,55 +54,34 @@ export function createCmHandles(cmHandleIds) {
}
})),
};
- const params = {
- headers: {'Content-Type': 'application/json'}
- };
- const response = http.post(url, JSON.stringify(payload), params);
- check(response, {
- 'status equals 200': (r) => r.status === 200,
- });
+ const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM);
+ check(response, { 'create CM-handles status equals 200': (r) => r.status === 200 });
return response;
}
-export function deleteCmHandles(cmHandleIds) {
+function deleteCmHandles(cmHandleIds) {
const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`;
const payload = {
"dmiPlugin": DMI_PLUGIN_URL,
"removedCmHandles": cmHandleIds,
};
- const params = {
- headers: {'Content-Type': 'application/json'}
- };
- const response = http.post(url, JSON.stringify(payload), params);
- check(response, {
- 'status equals 200': (r) => r.status === 200,
- });
+ const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM);
+ check(response, { 'delete CM-handles status equals 200': (r) => r.status === 200 });
return response;
}
-export function waitForCmHandlesToBeReady(timeOutInSeconds) {
- const pollingIntervalInSeconds = 10;
- const maxRetries = Math.ceil(timeOutInSeconds / pollingIntervalInSeconds);
+function waitForAllCmHandlesToBeReady() {
+ const POLLING_INTERVAL_SECONDS = 5;
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}/${TOTAL_CM_HANDLES} CM handles are READY`);
- if (cmHandlesReady === TOTAL_CM_HANDLES) {
- console.log(`All ${TOTAL_CM_HANDLES} CM handles are READY`);
- return;
- }
- }
- fail(`Timed out after ${timeOutInSeconds} seconds waiting for ${TOTAL_CM_HANDLES} CM handles to be READY`);
+ do {
+ sleep(POLLING_INTERVAL_SECONDS);
+ cmHandlesReady = getNumberOfReadyCmHandles();
+ console.log(`${cmHandlesReady}/${TOTAL_CM_HANDLES} CM handles are READY`);
+ } while (cmHandlesReady < TOTAL_CM_HANDLES);
}
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;
+ const response = executeCmHandleIdSearch('readyCmHandles');
+ const arrayOfCmHandleIds = JSON.parse(response.body);
+ return arrayOfCmHandleIds.length;
}