From f66694a076be41d83693423dec818493bcf66715 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Mon, 10 Jun 2024 21:32:12 +0100 Subject: [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 Change-Id: Ia9ebf61d21044b43063bde153f9c526e67d607c8 --- k6-tests/ncmp/1-create-cmhandles.js | 33 ++------- k6-tests/ncmp/10-mixed-load-test.js | 15 +--- k6-tests/ncmp/11-delete-cmhandles.js | 19 ++--- k6-tests/ncmp/2-wait-for-cmhandles-to-be-ready.js | 34 +-------- k6-tests/ncmp/3-passthrough-read.js | 16 +--- k6-tests/ncmp/4-id-search-no-filter.js | 4 +- k6-tests/ncmp/5-search-no-filter.js | 4 +- k6-tests/ncmp/6-id-search-public-property.js | 4 +- k6-tests/ncmp/7-search-public-property.js | 4 +- k6-tests/ncmp/8-id-search-module.js | 4 +- k6-tests/ncmp/9-search-module.js | 4 +- k6-tests/ncmp/common/cmhandle-crud.js | 90 +++++++++++++++++++++++ k6-tests/ncmp/common/passthrough-read.js | 36 +++++++++ k6-tests/ncmp/common/search-base.js | 68 +++++++++++++++++ k6-tests/ncmp/common/utils.js | 63 ++++++++++++++++ k6-tests/ncmp/search-base.js | 64 ---------------- k6-tests/ncmp/utils.js | 61 --------------- 17 files changed, 290 insertions(+), 233 deletions(-) create mode 100644 k6-tests/ncmp/common/cmhandle-crud.js create mode 100644 k6-tests/ncmp/common/passthrough-read.js create mode 100644 k6-tests/ncmp/common/search-base.js create mode 100644 k6-tests/ncmp/common/utils.js delete mode 100644 k6-tests/ncmp/search-base.js delete mode 100644 k6-tests/ncmp/utils.js diff --git a/k6-tests/ncmp/1-create-cmhandles.js b/k6-tests/ncmp/1-create-cmhandles.js index 60594c712..9a5c22ad3 100644 --- a/k6-tests/ncmp/1-create-cmhandles.js +++ b/k6-tests/ncmp/1-create-cmhandles.js @@ -18,16 +18,9 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; import exec from 'k6/execution'; -import { check } from 'k6'; -import { - NCMP_BASE_URL, - DMI_PLUGIN_URL, - TOTAL_CM_HANDLES, - makeBatchOfCmHandleIds, - makeCustomSummaryReport -} from './utils.js'; +import { TOTAL_CM_HANDLES, makeBatchOfCmHandleIds, makeCustomSummaryReport } from './common/utils.js'; +import { createCmHandles } from './common/cmhandle-crud.js'; const BATCH_SIZE = 100; export const options = { @@ -40,25 +33,9 @@ export const options = { }; export default function () { - const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(BATCH_SIZE, exec.scenario.iterationInTest); - const payload = { - "dmiPlugin": DMI_PLUGIN_URL, - "createdCmHandles": nextBatchOfCmHandleIds.map(cmHandleId => ({ - "cmHandle": cmHandleId, - "cmHandleProperties": {"neType": "RadioNode"}, - "publicCmHandleProperties": { - "Color": "yellow", - "Size": "small", - "Shape": "cube" - } - })), - }; - const response = http.post(NCMP_BASE_URL + '/ncmpInventory/v1/ch', JSON.stringify(payload), { - headers: {'Content-Type': 'application/json'}, - }); - check(response, { - 'status equals 200': (r) => r.status === 200, - }); + const batchNumber = exec.scenario.iterationInTest; + const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(BATCH_SIZE, batchNumber); + createCmHandles(nextBatchOfCmHandleIds); } export function handleSummary(data) { diff --git a/k6-tests/ncmp/10-mixed-load-test.js b/k6-tests/ncmp/10-mixed-load-test.js index 4bb0297d6..afa91af20 100644 --- a/k6-tests/ncmp/10-mixed-load-test.js +++ b/k6-tests/ncmp/10-mixed-load-test.js @@ -18,10 +18,9 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; -import { check } from 'k6'; -import { NCMP_BASE_URL, getRandomCmHandleId, makeCustomSummaryReport } from './utils.js' -import { executeCmHandleSearch, executeCmHandleIdSearch } from './search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js' +import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js'; +import { passthroughRead } from './common/passthrough-read.js'; export const options = { scenarios: { @@ -56,13 +55,7 @@ export const options = { }; export function passthrough_read() { - const cmHandleId = getRandomCmHandleId(); - const datastoreName = 'ncmp-datastore%3Apassthrough-operational'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=x&include-descendants=true` - const response = http.get(url); - check(response, { - 'status equals 200': (r) => r.status === 200, - }); + passthroughRead(); } export function id_search_module() { diff --git a/k6-tests/ncmp/11-delete-cmhandles.js b/k6-tests/ncmp/11-delete-cmhandles.js index 073d1d083..534b3de32 100644 --- a/k6-tests/ncmp/11-delete-cmhandles.js +++ b/k6-tests/ncmp/11-delete-cmhandles.js @@ -18,10 +18,9 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; import exec from 'k6/execution'; -import { check } from 'k6'; -import { NCMP_BASE_URL, TOTAL_CM_HANDLES, makeBatchOfCmHandleIds, makeCustomSummaryReport } from './utils.js'; +import { TOTAL_CM_HANDLES, makeBatchOfCmHandleIds, makeCustomSummaryReport } from './common/utils.js'; +import { deleteCmHandles } from './common/cmhandle-crud.js'; const BATCH_SIZE = 100; export const options = { @@ -34,17 +33,9 @@ export const options = { }; export default function () { - const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(BATCH_SIZE, exec.scenario.iterationInTest); - const payload = { - "dmiPlugin": "http://ncmp-dmi-plugin-demo-and-csit-stub:8092", - "removedCmHandles": nextBatchOfCmHandleIds, - }; - const response = http.post(NCMP_BASE_URL + '/ncmpInventory/v1/ch', JSON.stringify(payload), { - headers: {'Content-Type': 'application/json'}, - }); - check(response, { - 'status equals 200': (r) => r.status === 200, - }); + const batchNumber = exec.scenario.iterationInTest; + const nextBatchOfCmHandleIds = makeBatchOfCmHandleIds(BATCH_SIZE, batchNumber); + deleteCmHandles(nextBatchOfCmHandleIds); } export function handleSummary(data) { 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 5d54c60f4..cce85ab7c 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) { diff --git a/k6-tests/ncmp/3-passthrough-read.js b/k6-tests/ncmp/3-passthrough-read.js index 84050b83a..39eb4ad67 100644 --- a/k6-tests/ncmp/3-passthrough-read.js +++ b/k6-tests/ncmp/3-passthrough-read.js @@ -18,10 +18,9 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; -import { check } from 'k6'; -import { Trend } from "k6/metrics"; -import { NCMP_BASE_URL, getRandomCmHandleId, makeCustomSummaryReport } from './utils.js' +import { Trend } from 'k6/metrics'; +import { passthroughRead } from './common/passthrough-read.js' +import { makeCustomSummaryReport } from './common/utils.js' let ncmpOverheadTrend = new Trend("ncmp_overhead"); @@ -36,14 +35,7 @@ export const options = { // The function that defines VU logic. export default function () { - const cmHandleId = getRandomCmHandleId(); - const datastoreName = 'ncmp-datastore%3Apassthrough-operational'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleId}/data/ds/${datastoreName}?resourceIdentifier=x&include-descendants=true` - const response = http.get(url); - check(response, { - 'status equals 200': (r) => r.status === 200, - }); - + const response = passthroughRead(); // Calculate overhead assuming DMI data delay is 2500ms. const dmiDelay = 2500; // This should be same as value DATA_FOR_CM_HANDLE_DELAY_MS in docker-compose.yml const overhead = response.timings.duration - dmiDelay; diff --git a/k6-tests/ncmp/4-id-search-no-filter.js b/k6-tests/ncmp/4-id-search-no-filter.js index ed8d77f2e..3863b5d78 100644 --- a/k6-tests/ncmp/4-id-search-no-filter.js +++ b/k6-tests/ncmp/4-id-search-no-filter.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleIdSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleIdSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 5, diff --git a/k6-tests/ncmp/5-search-no-filter.js b/k6-tests/ncmp/5-search-no-filter.js index 73fa82787..67c9d5982 100644 --- a/k6-tests/ncmp/5-search-no-filter.js +++ b/k6-tests/ncmp/5-search-no-filter.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 4, diff --git a/k6-tests/ncmp/6-id-search-public-property.js b/k6-tests/ncmp/6-id-search-public-property.js index 543ee1a87..25bffaf25 100644 --- a/k6-tests/ncmp/6-id-search-public-property.js +++ b/k6-tests/ncmp/6-id-search-public-property.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleIdSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleIdSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 5, diff --git a/k6-tests/ncmp/7-search-public-property.js b/k6-tests/ncmp/7-search-public-property.js index cb39b54d9..53f069d02 100644 --- a/k6-tests/ncmp/7-search-public-property.js +++ b/k6-tests/ncmp/7-search-public-property.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 4, diff --git a/k6-tests/ncmp/8-id-search-module.js b/k6-tests/ncmp/8-id-search-module.js index d058a1bf1..8200ea28c 100644 --- a/k6-tests/ncmp/8-id-search-module.js +++ b/k6-tests/ncmp/8-id-search-module.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleIdSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleIdSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 5, diff --git a/k6-tests/ncmp/9-search-module.js b/k6-tests/ncmp/9-search-module.js index c6bbb06db..eafef99b3 100644 --- a/k6-tests/ncmp/9-search-module.js +++ b/k6-tests/ncmp/9-search-module.js @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -import { executeCmHandleSearch } from './search-base.js'; -import { makeCustomSummaryReport } from "./utils.js"; +import { executeCmHandleSearch } from './common/search-base.js'; +import { makeCustomSummaryReport } from './common/utils.js'; export const options = { vus: 4, diff --git a/k6-tests/ncmp/common/cmhandle-crud.js b/k6-tests/ncmp/common/cmhandle-crud.js new file mode 100644 index 000000000..0c3e116a1 --- /dev/null +++ b/k6-tests/ncmp/common/cmhandle-crud.js @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import http from 'k6/http'; +import { check, sleep, fail } from 'k6'; +import { NCMP_BASE_URL, DMI_PLUGIN_URL, TOTAL_CM_HANDLES } from './utils.js'; + +export function createCmHandles(cmHandleIds) { + const url = `${NCMP_BASE_URL}/ncmpInventory/v1/ch`; + const payload = { + "dmiPlugin": DMI_PLUGIN_URL, + "createdCmHandles": cmHandleIds.map(cmHandleId => ({ + "cmHandle": cmHandleId, + "cmHandleProperties": {"neType": "RadioNode"}, + "publicCmHandleProperties": { + "Color": "yellow", + "Size": "small", + "Shape": "cube" + } + })), + }; + 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, + }); + return response; +} + +export 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, + }); + return response; +} + +export function waitForCmHandlesToBeReady(timeOutInSeconds) { + 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}/${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`); +} + +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; +} diff --git a/k6-tests/ncmp/common/passthrough-read.js b/k6-tests/ncmp/common/passthrough-read.js new file mode 100644 index 000000000..e4e937c9c --- /dev/null +++ b/k6-tests/ncmp/common/passthrough-read.js @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import http from 'k6/http'; +import { check } from 'k6'; +import { NCMP_BASE_URL, getRandomCmHandleId } from './utils.js'; + +export function passthroughRead() { + const cmHandleId = getRandomCmHandleId(); + const resourceIdentifier = 'my-resource-identifier'; + const includeDescendants = true; + 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 new file mode 100644 index 000000000..f833a5388 --- /dev/null +++ b/k6-tests/ncmp/common/search-base.js @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +import http from 'k6/http'; +import { check } from 'k6'; +import { NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js'; + +const SEARCH_PARAMETERS_PER_SCENARIO = { + 'no-filter': {}, + 'module': { + 'cmHandleQueryParameters': [ + { + 'conditionName': 'hasAllModules', + 'conditionParameters': [{'moduleName': 'ietf-yang-types-1'}] + } + ] + }, + 'property': { + 'cmHandleQueryParameters': [ + { + 'conditionName': 'hasAllProperties', + 'conditionParameters': [{'Color': 'yellow'}] + } + ] + } +}; + +export function executeCmHandleSearch(scenario) { + executeSearchRequest('searches', scenario); +} + +export function executeCmHandleIdSearch(scenario) { + 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, + }); +} diff --git a/k6-tests/ncmp/common/utils.js b/k6-tests/ncmp/common/utils.js new file mode 100644 index 000000000..1fb9b8e67 --- /dev/null +++ b/k6-tests/ncmp/common/utils.js @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +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 = 20000 + +/** + * Generates a batch of CM-handle IDs based on batch size and number. + * @param {number} batchSize - Size of each batch. + * @param {number} batchNumber - Number of the batch. + * @returns {string[]} Array of CM-handle IDs, for example ['ch-201', 'ch-202' ... 'ch-300'] + */ +export function makeBatchOfCmHandleIds(batchSize, batchNumber) { + const batchOfIds = []; + const startIndex = 1 + batchNumber * batchSize; + for (let i = 0; i < batchSize; i++) { + let cmHandleId = 'ch-' + (startIndex + i); + batchOfIds.push(cmHandleId); + } + return batchOfIds; +} + +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; +} + diff --git a/k6-tests/ncmp/search-base.js b/k6-tests/ncmp/search-base.js deleted file mode 100644 index 04b644425..000000000 --- a/k6-tests/ncmp/search-base.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -import http from 'k6/http'; -import { check } from 'k6'; -import { NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js'; - -const SEARCH_PARAMETERS_PER_SCENARIO = { - 'no-filter': {}, - 'module': { - 'cmHandleQueryParameters': [ - { - 'conditionName': 'hasAllModules', - 'conditionParameters': [{'moduleName': 'ietf-yang-types-1'}] - } - ] - }, - 'property': { - 'cmHandleQueryParameters': [ - { - 'conditionName': 'hasAllProperties', - 'conditionParameters': [{'Color': 'yellow'}] - } - ] - } -}; - -export function executeCmHandleSearch(scenario) { - executeSearchRequest('searches', scenario); -} - -export function executeCmHandleIdSearch(scenario) { - executeSearchRequest('id-searches', scenario); -} - -function executeSearchRequest(searchType, scenario) { - const searchParameter = JSON.stringify(SEARCH_PARAMETERS_PER_SCENARIO[scenario]); - const response = http.post(NCMP_BASE_URL + '/ncmp/v1/ch/' + searchType, searchParameter, { - headers: {'Content-Type': 'application/json'}, - }); - check(response, { - 'status equals 200': (r) => r.status === 200, - }); - check(JSON.parse(response.body), { - 'returned list has expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES, - }); -} diff --git a/k6-tests/ncmp/utils.js b/k6-tests/ncmp/utils.js deleted file mode 100644 index 18a894052..000000000 --- a/k6-tests/ncmp/utils.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -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 = 20000 - -/* - * Makes a batch of CM-handle IDs. - * Given a batchSize=100 and batchNumber=2, it will generate ['ch-201', 'ch-202' ... 'ch-300'] - */ -export function makeBatchOfCmHandleIds(batchSize, batchNumber) { - const batchOfIds = []; - const startIndex = 1 + batchNumber * batchSize; - for (let i = 0; i < batchSize; i++) { - let cmHandleId = 'ch-' + (startIndex + i); - batchOfIds.push(cmHandleId); - } - return batchOfIds; -} - -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; -} - -- cgit 1.2.3-korg