danielhanrahan | 4e9f68c | 2024-06-28 13:43:35 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | import { check } from 'k6'; |
| 22 | import { Gauge } from 'k6/metrics'; |
| 23 | import { TOTAL_CM_HANDLES, makeCustomSummaryReport, recordTimeInSeconds } from './common/utils.js'; |
| 24 | import { registerAllCmHandles, deregisterAllCmHandles } from './common/cmhandle-crud.js'; |
| 25 | import { executeCmHandleSearch, executeCmHandleIdSearch } from './common/search-base.js'; |
| 26 | import { passthroughRead } from './common/passthrough-read.js'; |
| 27 | |
| 28 | let cmHandlesCreatedPerSecondGauge = new Gauge('cmhandles_created_per_second'); |
| 29 | let cmHandlesDeletedPerSecondGauge = new Gauge('cmhandles_deleted_per_second'); |
| 30 | |
| 31 | const DURATION = '15m'; |
| 32 | |
| 33 | export 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 | |
| 68 | export function setup() { |
| 69 | const totalRegistrationTimeInSeconds = recordTimeInSeconds(registerAllCmHandles); |
| 70 | cmHandlesCreatedPerSecondGauge.add(TOTAL_CM_HANDLES / totalRegistrationTimeInSeconds); |
| 71 | } |
| 72 | |
| 73 | export function teardown() { |
| 74 | const totalDeregistrationTimeInSeconds = recordTimeInSeconds(deregisterAllCmHandles); |
| 75 | cmHandlesDeletedPerSecondGauge.add(TOTAL_CM_HANDLES / totalDeregistrationTimeInSeconds); |
| 76 | } |
| 77 | |
| 78 | export function passthrough_read() { |
| 79 | const response = passthroughRead(); |
| 80 | check(response, { 'passthrough read status equals 200': (r) => r.status === 200 }); |
| 81 | } |
| 82 | |
| 83 | export 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 | |
| 89 | export 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 | |
| 95 | export function handleSummary(data) { |
| 96 | return { |
| 97 | stdout: makeCustomSummaryReport(data, options), |
| 98 | }; |
| 99 | } |