blob: 91a38d99ce5732ee2735f32502e665b8214c5469 [file] [log] [blame]
danielhanrahan4e9f68c2024-06-28 13:43:35 +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 { check } from 'k6';
22import { Gauge } from 'k6/metrics';
23import { TOTAL_CM_HANDLES, makeCustomSummaryReport, recordTimeInSeconds } from './common/utils.js';
24import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js';
25import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js';
26import { passthroughRead } from './common/passthrough-read.js';
27
28let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second');
29let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second');
30
31const DURATION = '15m';
32
33export const options = {
34 setupTimeout: '6m',
35 teardownTimeout: '6m',
36 scenarios: {
37 passthrough_read: {
38 executor: 'constant-vus',
39 exec: 'passthrough_read',
40 vus: 10,
41 duration: DURATION,
42 },
43 id_search_module: {
44 executor: 'constant-vus',
45 exec: 'id_search_module',
46 vus: 3,
47 duration: DURATION,
48 },
49 cm_search_module: {
50 executor: 'constant-vus',
51 exec: 'cm_search_module',
52 vus: 3,
53 duration: DURATION,
54 },
55 },
56 thresholds: {
57 'cmhandles_created_per_second': ['value >= 22'],
58 'cmhandles_deleted_per_second': ['value >= 22'],
59 'http_req_failed{scenario:passthrough_read}': ['rate == 0'],
60 'http_req_failed{scenario:id_search_module}': ['rate == 0'],
61 'http_req_failed{scenario:cm_search_module}': ['rate == 0'],
62 'http_req_duration{scenario:passthrough_read}': ['avg <= 2600'], // DMI delay + 100 ms
63 'http_req_duration{scenario:id_search_module}': ['avg <= 625'],
64 'http_req_duration{scenario:cm_search_module}': ['avg <= 13000'],
65 },
66};
67
68export function setup() {
69 const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles);
70 cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds);
71}
72
73export function teardown() {
74 const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles);
75 cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds);
76}
77
78export function passthrough_read() {
79 const response = passthroughRead();
80 check(response, { 'passthrough read status equals 200': (r) => r.status === 200 });
81}
82
83export function id_search_module() {
84 const response = executeCmHandleIdSearch('module');
85 check(response, { 'module ID search status equals 200': (r) => r.status === 200 });
86 check(JSON.parse(response.body), { 'module ID search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
87}
88
89export function cm_search_module() {
90 const response = executeCmHandleSearch('module');
91 check(response, { 'module search status equals 200': (r) => r.status === 200 });
92 check(JSON.parse(response.body), { 'module search returned expected CM-handles': (arr) => arr.length === TOTAL_CM_HANDLES });
93}
94
95export function handleSummary(data) {
96 return {
97 stdout: makeCustomSummaryReport(data, options),
98 };
99}