aboutsummaryrefslogtreecommitdiffstats
path: root/k6-tests/ncmp/common
diff options
context:
space:
mode:
Diffstat (limited to 'k6-tests/ncmp/common')
-rw-r--r--k6-tests/ncmp/common/cmhandle-crud.js75
-rw-r--r--k6-tests/ncmp/common/passthrough-read.js4
-rw-r--r--k6-tests/ncmp/common/search-base.js28
-rw-r--r--k6-tests/ncmp/common/utils.js45
4 files changed, 75 insertions, 77 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;
}
diff --git a/k6-tests/ncmp/common/passthrough-read.js b/k6-tests/ncmp/common/passthrough-read.js
index e4e937c9c0..89ed15af79 100644
--- a/k6-tests/ncmp/common/passthrough-read.js
+++ b/k6-tests/ncmp/common/passthrough-read.js
@@ -19,7 +19,6 @@
*/
import http from 'k6/http';
-import { check } from 'k6';
import { NCMP_BASE_URL, getRandomCmHandleId } from './utils.js';
export function passthroughRead() {
@@ -29,8 +28,5 @@ export function passthroughRead() {
const datastoreName = 'ncmp-datastore:passthrough-operational';
const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}`
const response = http.get(url);
- check(response, {
- 'status equals 200': (r) => r.status === 200,
- });
return response;
}
diff --git a/k6-tests/ncmp/common/search-base.js b/k6-tests/ncmp/common/search-base.js
index 816bacac56..bc964856af 100644
--- a/k6-tests/ncmp/common/search-base.js
+++ b/k6-tests/ncmp/common/search-base.js
@@ -19,8 +19,7 @@
*/
import http from 'k6/http';
-import { check } from 'k6';
-import { NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js';
+import { NCMP_BASE_URL, CONTENT_TYPE_JSON_PARAM } from './utils.js';
const SEARCH_PARAMETERS_PER_SCENARIO = {
'module': {
@@ -30,30 +29,29 @@ const SEARCH_PARAMETERS_PER_SCENARIO = {
'conditionParameters': [{'moduleName': 'ietf-yang-types-1'}]
}
]
+ },
+ 'readyCmHandles': {
+ 'cmHandleQueryParameters': [
+ {
+ 'conditionName': 'cmHandleWithCpsPath',
+ 'conditionParameters': [{'cpsPath': '//state[@cm-handle-state="READY"]'}]
+ }
+ ]
}
};
export function executeCmHandleSearch(scenario) {
- executeSearchRequest('searches', scenario);
+ return executeSearchRequest('searches', scenario);
}
export function executeCmHandleIdSearch(scenario) {
- executeSearchRequest('id-searches', scenario);
+ return executeSearchRequest('id-searches', scenario);
}
function executeSearchRequest(searchType, scenario) {
const searchParameters = SEARCH_PARAMETERS_PER_SCENARIO[scenario];
const payload = JSON.stringify(searchParameters);
const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${searchType}`;
- const params = {
- headers: {'Content-Type': 'application/json'}
- };
- const response = http.post(url, payload, params);
- check(response, {
- 'status equals 200': (r) => r.status === 200,
- });
- const responseData = JSON.parse(response.body);
- check(responseData, {
- 'returned list has expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES,
- });
+ const response = http.post(url, payload, CONTENT_TYPE_JSON_PARAM);
+ return response;
}
diff --git a/k6-tests/ncmp/common/utils.js b/k6-tests/ncmp/common/utils.js
index 55ef60a2e7..54b4c3a099 100644
--- a/k6-tests/ncmp/common/utils.js
+++ b/k6-tests/ncmp/common/utils.js
@@ -20,8 +20,17 @@
export const NCMP_BASE_URL = 'http://localhost:8883';
export const DMI_PLUGIN_URL = 'http://ncmp-dmi-plugin-demo-and-csit-stub:8092';
-export const TOTAL_CM_HANDLES = Number(__ENV.TOTAL_CM_HANDLES) || 20000;
-export const REGISTRATION_BATCH_SIZE = Number(__ENV.REGISTRATION_BATCH_SIZE) || 100;
+export const TOTAL_CM_HANDLES = 20000;
+export const REGISTRATION_BATCH_SIZE = 100;
+export const CONTENT_TYPE_JSON_PARAM = { headers: {'Content-Type': 'application/json'} };
+
+export function recordTimeInSeconds(functionToExecute) {
+ const startTimeInMillis = Date.now();
+ functionToExecute();
+ const endTimeInMillis = Date.now();
+ const totalTimeInSeconds = (endTimeInMillis - startTimeInMillis) / 1000.0;
+ return totalTimeInSeconds;
+}
/**
* Generates a batch of CM-handle IDs based on batch size and number.
@@ -33,7 +42,7 @@ export function makeBatchOfCmHandleIds(batchSize, batchNumber) {
const batchOfIds = [];
const startIndex = 1 + batchNumber * batchSize;
for (let i = 0; i < batchSize; i++) {
- let cmHandleId = 'ch-' + (startIndex + i);
+ let cmHandleId = `ch-${startIndex + i}`;
batchOfIds.push(cmHandleId);
}
return batchOfIds;
@@ -43,22 +52,20 @@ export function getRandomCmHandleId() {
return `ch-${Math.floor(Math.random() * TOTAL_CM_HANDLES) + 1}`;
}
-function removeBracketsAndQuotes(str) {
- return str.replace(/\[|\]|"/g, '');
-}
-
export function makeCustomSummaryReport(data, options) {
- const moduleName = `${__ENV.K6_MODULE_NAME}`;
- let body = ``;
- for (const condition in options.thresholds) {
- let limit = JSON.stringify(options.thresholds[condition])
- limit = removeBracketsAndQuotes(limit)
- let limitKey = limit.split(' ')[0]
- const actual = Math.ceil(data.metrics[condition].values[limitKey])
- const result = data.metrics[condition].thresholds[limit].ok ? 'PASS' : 'FAIL'
- const row = `${moduleName}\t${condition}\t${limit}\t${actual}\t${result}\n`;
- body += row;
- }
- return body;
+ let summaryCsv = '#,Test Name,Unit,Limit,Actual\n';
+ summaryCsv += makeSummaryCsvLine(1, 'Registration of CM-handles', 'CM-handles/second', 'cmhandles_created_per_second', data, options);
+ summaryCsv += makeSummaryCsvLine(2, 'De-registration of CM-handles', 'CM-handles/second', 'cmhandles_deleted_per_second', data, options);
+ summaryCsv += makeSummaryCsvLine(3, 'CM-handle ID search with Module filter', 'milliseconds', 'http_req_duration{scenario:id_search_module}', data, options);
+ summaryCsv += makeSummaryCsvLine(4, 'CM-handle search with Module filter', 'milliseconds', 'http_req_duration{scenario:cm_search_module}', data, options);
+ summaryCsv += makeSummaryCsvLine(5, 'Synchronous single CM-handle pass-through read', 'milliseconds', 'http_req_duration{scenario:passthrough_read}', data, options);
+ return summaryCsv;
}
+function makeSummaryCsvLine(testCase, testName, unit, thresholdInK6, data, options) {
+ const thresholdArray = JSON.parse(JSON.stringify(options.thresholds[thresholdInK6]));
+ const thresholdString = thresholdArray[0];
+ const [thresholdKey, thresholdOperator, thresholdValue] = thresholdString.split(/\s+/);
+ const actualValue = data.metrics[thresholdInK6].values[thresholdKey].toFixed(3);
+ return `${testCase},${testName},${unit},${thresholdValue},${actualValue}\n`;
+}