blob: 4ecadde2b4892953e001a458d43ff19b0a640c87 [file] [log] [blame]
danielhanrahanc0b6f3a2024-04-29 16:16:42 +01001/*
2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
19 */
20
21import http from 'k6/http';
22import { sleep, fail } from 'k6';
halil.cakal0613fbd2024-05-27 16:06:59 +010023import { makeCustomSummaryReport, NCMP_BASE_URL, TOTAL_CM_HANDLES } from './utils.js';
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010024
25export const options = {
halil.cakal0613fbd2024-05-27 16:06:59 +010026 vus: 1,
27 iterations: 1,
28 thresholds: {
29 http_req_failed: ['rate == 0'],
30 iteration_duration: ['max <= 300_000'], // 5 minutes
31 },
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010032};
33
halil.cakal0613fbd2024-05-27 16:06:59 +010034export default function () {
danielhanrahanc0b6f3a2024-04-29 16:16:42 +010035 waitForCmHandlesToBeReady(TOTAL_CM_HANDLES);
36}
37
38function waitForCmHandlesToBeReady(totalCmHandles) {
39 const timeOutInSeconds = 6 * 60;
40 const pollingIntervalInSeconds = 10;
41 const maxRetries = Math.ceil(timeOutInSeconds / pollingIntervalInSeconds);
42 let cmHandlesReady = 0;
43 for (let currentTry = 0; currentTry <= maxRetries; currentTry++) {
44 sleep(pollingIntervalInSeconds);
45 try {
46 cmHandlesReady = getNumberOfReadyCmHandles();
47 } catch (error) {
48 console.error(`Attempt ${currentTry + 1} - Error fetching CM handles: ${error.message}`);
49 }
50 console.log(`Attempt ${currentTry + 1} - ${cmHandlesReady}/${totalCmHandles} CM handles are READY`);
51 if (cmHandlesReady === totalCmHandles) {
52 console.log(`All ${totalCmHandles} CM handles are READY`);
53 return;
54 }
55 }
56 fail(`Timed out after ${timeoutInSeconds} seconds waiting for ${totalCmHandles} CM handles to be READY`);
57}
58
59function getNumberOfReadyCmHandles() {
60 const endpointUrl = `${NCMP_BASE_URL}/cps/api/v2/dataspaces/NCMP-Admin/anchors/ncmp-dmi-registry/node?xpath=/dmi-registry&descendants=all`;
61 const jsonData = http.get(endpointUrl).json();
62 const cmHandles = jsonData[0]["dmi-reg:dmi-registry"]["cm-handles"];
63 return cmHandles.filter(cmhandle => cmhandle['state']['cm-handle-state'] === 'READY').length;
64}
halil.cakal0613fbd2024-05-27 16:06:59 +010065
66export function handleSummary(data) {
67 return {
68 stdout: makeCustomSummaryReport(data, options),
69 };
70}