From 2a132c87c6c05b52c56eb344e5450416dc535271 Mon Sep 17 00:00:00 2001 From: svariant Date: Wed, 25 Sep 2024 09:14:02 +0200 Subject: [PATCH 1/5] [PPANTT-73] feat: Init performance tests --- .devops/performance-test-pipelines.yaml | 113 ------------------ .devops/performance-test-pipelines.yml | 54 +++++++++ perfomance-test/README.md | 15 ++- perfomance-test/docker-compose.yaml | 27 +++++ perfomance-test/nginx/nginx.conf | 16 +++ perfomance-test/run_performance_test.sh | 35 ++++++ perfomance-test/src/dev.environment.json | 8 ++ perfomance-test/src/local.environment.json | 8 ++ .../src/modules/payment_options_client.js | 9 ++ perfomance-test/src/package.json | 8 ++ .../src/payment_options_service_test.js | 5 + perfomance-test/src/test-types/constant.json | 50 ++++++++ perfomance-test/src/test-types/load.json | 34 ++++++ perfomance-test/src/test-types/spike.json | 38 ++++++ perfomance-test/src/test-types/stress.json | 61 ++++++++++ perfomance-test/src/uat.environment.json | 8 ++ 16 files changed, 375 insertions(+), 114 deletions(-) delete mode 100644 .devops/performance-test-pipelines.yaml create mode 100644 .devops/performance-test-pipelines.yml create mode 100644 perfomance-test/docker-compose.yaml create mode 100644 perfomance-test/nginx/nginx.conf create mode 100644 perfomance-test/run_performance_test.sh create mode 100644 perfomance-test/src/dev.environment.json create mode 100644 perfomance-test/src/local.environment.json create mode 100644 perfomance-test/src/modules/payment_options_client.js create mode 100644 perfomance-test/src/package.json create mode 100644 perfomance-test/src/payment_options_service_test.js create mode 100644 perfomance-test/src/test-types/constant.json create mode 100644 perfomance-test/src/test-types/load.json create mode 100644 perfomance-test/src/test-types/spike.json create mode 100644 perfomance-test/src/test-types/stress.json create mode 100644 perfomance-test/src/uat.environment.json diff --git a/.devops/performance-test-pipelines.yaml b/.devops/performance-test-pipelines.yaml deleted file mode 100644 index d1732b5..0000000 --- a/.devops/performance-test-pipelines.yaml +++ /dev/null @@ -1,113 +0,0 @@ -# azure-pipelines.yml -trigger: none - -parameters: - - name: "ENVIRONMENT" - displayName: "Environment" - type: string - values: - - "dev" - - "uat" - - "prod" - default: "uat" - - name: "TEST_TYPE" - displayName: "Test type" - type: string - values: - - "load" - - "spike" - - "stress" - - "constant" - - "smoke" - - "ramp" - default: "constant" - - name: "SCRIPT" - displayName: "Script name" - type: string - values: - - "notice_single_generation" - - "notice_massive_generation" - - "notice_single_generation_on_massive" - default: "notice_single_generation" - - name: "DB_NAME" - displayName: "DB name" - type: string - values: - - printnoticek6 - - name: "TEMPLATE_ID" - displayName: "Template to use" - type: string - values: - - "TemplateSingleInstalment" - - "TemplateSingleInstalmentPoste" - - "TemplateInstalments" - - "TemplateInstalmentsPoste" - default: "TemplateSingleInstalment" - - name: "PROCESS_TIME" - displayName: "Process time for a massive request (in seconds)" - type: number - default: 5 - - name: "NUMBER_OF_MASSIVE_ELEMENTS" - displayName: "Number of notices in a massive request" - type: number - default: 10 -variables: - ${{ if eq(parameters['ENVIRONMENT'], 'dev') }}: - poolImage: 'pagopa-dev-loadtest-linux' - API_SUBSCRIPTION_KEY: "$(DEV_API_SUBSCRIPTION_KEY)" - blobInstitutionsConnectionString: "$(DEV_BLOB_INSTITUTIONS_CONNECTION_STRING)" - blobNoticesConnectionString: "$(DEV_BLOB_NOTICES_CONNECTION_STRING)" - mongoNoticesConnectionString: "$(DEV_MONGO_NOTICES_CONNECTION_STRING)" - - ${{ if eq(parameters['ENVIRONMENT'], 'uat') }}: - poolImage: 'pagopa-uat-loadtest-linux' - API_SUBSCRIPTION_KEY: "$(UAT_API_SUBSCRIPTION_KEY)" - blobInstitutionsConnectionString: "$(UAT_BLOB_INSTITUTIONS_CONNECTION_STRING)" - blobNoticesConnectionString: "$(UAT_BLOB_NOTICES_CONNECTION_STRING)" - mongoNoticesConnectionString: "$(UAT_MONGO_NOTICES_CONNECTION_STRING)" - - ${{ if eq(parameters['ENVIRONMENT'], 'prod') }}: - poolImage: 'pagopa-uat-loadtest-linux' - API_SUBSCRIPTION_KEY: "$(PROD_API_SUBSCRIPTION_KEY)" - blobInstitutionsConnectionString: "$(PROD_BLOB_INSTITUTIONS_CONNECTION_STRING)" - blobNoticesConnectionString: "$(PROD_BLOB_NOTICES_CONNECTION_STRING)" - mongoNoticesConnectionString: "$(PROD_MONGO_NOTICES_CONNECTION_STRING)" - -pool: - name: $(poolImage) - -steps: - - script: | - cd ./performance-test/src - docker pull grafana/k6 - displayName: Pull k6 image - - script: | - cd ./performance-test/src - docker build -f ./DockerfilePre -t exec-node . - docker run --rm --name initToRunk6 -e BLOB_INSTITUTIONS_CONN_STRING=${BLOB_INSTITUTIONS_CONN_STRING} -e BLOB_NOTICES_CONN_STRING=${BLOB_NOTICES_CONN_STRING} -e NOTICES_MONGO_CONN_STRING=${NOTICES_MONGO_CONN_STRING} -e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" exec-node - displayName: Precondition run perf test - env: - BLOB_INSTITUTIONS_CONN_STRING: ${{ variables.blobInstitutionsConnectionString }} - BLOB_NOTICES_CONN_STRING: ${{ variables.blobNoticesConnectionString }} - NOTICES_MONGO_CONN_STRING: ${{ variables.mongoNoticesConnectionString }} - NUMBER_OF_MASSIVE_ELEMENTS: ${{ parameters.NUMBER_OF_MASSIVE_ELEMENTS }} - ENVIRONMENT_STRING: ${{ parameters.ENVIRONMENT }} - - - script: | - cd ./performance-test - sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} ${{ parameters.SCRIPT }} ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY ${{ parameters.TEMPLATE_ID }} ${{ parameters.PROCESS_TIME }} ${{ parameters.NUMBER_OF_MASSIVE_ELEMENTS }} - displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }} - env: - OCP_APIM_SUBSCRIPTION_KEY: ${{ variables.API_SUBSCRIPTION_KEY }} - - - script: | - cd ./performance-test/src - docker build -f ./DockerfilePost -t exec-node . - docker run --rm --name initToRunk6 -e BLOB_INSTITUTIONS_CONN_STRING=${BLOB_INSTITUTIONS_CONN_STRING} -e BLOB_NOTICES_CONN_STRING=${BLOB_NOTICES_CONN_STRING} -e NOTICES_MONGO_CONN_STRING=${NOTICES_MONGO_CONN_STRING} -e ENVIRONMENT_STRING="${ENVIRONMENT_STRING}" exec-node - displayName: Teardown run perf test - env: - BLOB_INSTITUTIONS_CONN_STRING: ${{ variables.blobInstitutionsConnectionString }} - BLOB_NOTICES_CONN_STRING: ${{ variables.blobNoticesConnectionString }} - NOTICES_MONGO_CONN_STRING: ${{ variables.mongoNoticesConnectionString }} - ENVIRONMENT_STRING: ${{ parameters.ENVIRONMENT }} - diff --git a/.devops/performance-test-pipelines.yml b/.devops/performance-test-pipelines.yml new file mode 100644 index 0000000..3b9bb84 --- /dev/null +++ b/.devops/performance-test-pipelines.yml @@ -0,0 +1,54 @@ +# azure-pipelines.yml +trigger: none + +parameters: + - name: "ENVIRONMENT" + displayName: "Environment" + type: string + values: + - "dev" + - "uat" + default: "uat" + - name: "TEST_TYPE" + displayName: "Test type" + type: string + values: + - "load" + - "spike" + - "stress" + - "constant" + default: "constant" + - name: "SCRIPT" + displayName: "Script name" + type: string + values: + - "payment_options_service_test" + default: "payment_options_service_test" + - name: "DB_NAME" + displayName: "DB name" + type: string + values: + - pagopa_payment_options_servicek6 +variables: + ${{ if eq(parameters['ENVIRONMENT'], 'dev') }}: + poolImage: 'pagopa-dev-loadtest-linux' + API_SUBSCRIPTION_KEY: "$(DEV_API_SUBSCRIPTION_KEY)" + ${{ if eq(parameters['ENVIRONMENT'], 'uat') }}: + poolImage: 'pagopa-uat-loadtest-linux' + API_SUBSCRIPTION_KEY: "$(UAT_API_SUBSCRIPTION_KEY)" + +pool: + name: $(poolImage) + +steps: + - script: | + cd ./performance-test/src + docker pull grafana/k6 + displayName: Pull k6 image + - script: | + cd ./performance-test + sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} ${{ parameters.SCRIPT }} ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY + displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }} + env: + OCP_APIM_SUBSCRIPTION_KEY: ${{ variables.API_SUBSCRIPTION_KEY }} + diff --git a/perfomance-test/README.md b/perfomance-test/README.md index a7638d5..880ead4 100644 --- a/perfomance-test/README.md +++ b/perfomance-test/README.md @@ -1 +1,14 @@ -Put here the performance tests with K6 +# K6 tests + +This is a set of [k6](https://k6.io) tests. + +To invoke k6 tests use `run_performance_test.sh` script. + + +## How to run 🚀 + +Use this command to launch the tests: + +``` shell +sh run_performance_test.sh +``` \ No newline at end of file diff --git a/perfomance-test/docker-compose.yaml b/perfomance-test/docker-compose.yaml new file mode 100644 index 0000000..c07d21f --- /dev/null +++ b/perfomance-test/docker-compose.yaml @@ -0,0 +1,27 @@ +version: '3.3' +services: + k6: + image: grafana/k6 + container_name: k6 + volumes: + - '${PWD}/src:/scripts' + environment: + - OCP_APIM_SUBSCRIPTION_KEY=${ocp_apim_subscription_key} + - VARS=${env}.environment.json + - TEST_TYPE=/scripts/test-types/${type}.json + - K6_OUT=influxdb=http://nginx:8086/${db_name} + command: run /scripts/${script}.js + depends_on: + - nginx + + nginx: + image: nginx + container_name: nginx + volumes: + - '${PWD}/nginx/nginx.conf:/etc/nginx/nginx.conf' + environment: + - ENVIRONMENT=${env} + ports: + - "8086:8086" + - "80:80" + diff --git a/perfomance-test/nginx/nginx.conf b/perfomance-test/nginx/nginx.conf new file mode 100644 index 0000000..a9cc127 --- /dev/null +++ b/perfomance-test/nginx/nginx.conf @@ -0,0 +1,16 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 8086; + location / { + proxy_pass https://api.uat.platform.pagopa.it/shared/influxdb/v1/; + proxy_http_version 1.1; + proxy_set_header Host api.uat.platform.pagopa.it; + proxy_pass_request_headers on; + } + } +} + diff --git a/perfomance-test/run_performance_test.sh b/perfomance-test/run_performance_test.sh new file mode 100644 index 0000000..3c831b1 --- /dev/null +++ b/perfomance-test/run_performance_test.sh @@ -0,0 +1,35 @@ +# sh run_performance_test.sh + +ENVIRONMENT=$1 +TYPE=$2 +SCRIPT=$3 +DB_NAME=$4 +OCP_APIM_SUBSCRIPTION_KEY=$5 + +if [ -z "$ENVIRONMENT" ] +then + echo "No env specified: sh run_performance_test.sh " + exit 1 +fi + +if [ -z "$TYPE" ] +then + echo "No test type specified: sh run_performance_test.sh " + exit 1 +fi +if [ -z "$SCRIPT" ] +then + echo "No script name specified: sh run_performance_test.sh " + exit 1 +fi + +export env=${ENVIRONMENT} +export type=${TYPE} +export script=${SCRIPT} +export db_name=${DB_NAME} +export ocp_apim_subscription_key=${OCP_APIM_SUBSCRIPTION_KEY} + +stack_name=$(cd .. && basename "$PWD") +docker compose -p "${stack_name}-k6" up -d --remove-orphans --force-recreate --build +docker logs -f k6 +docker stop nginx \ No newline at end of file diff --git a/perfomance-test/src/dev.environment.json b/perfomance-test/src/dev.environment.json new file mode 100644 index 0000000..97692f8 --- /dev/null +++ b/perfomance-test/src/dev.environment.json @@ -0,0 +1,8 @@ +{ + "environment": [ + { + "env": "dev", + "paymentOptionsServiceURIBasePath": "https://api.dev.platform.pagopa.it/payment-options/v1" // TODO + } + ] +} diff --git a/perfomance-test/src/local.environment.json b/perfomance-test/src/local.environment.json new file mode 100644 index 0000000..4e44e80 --- /dev/null +++ b/perfomance-test/src/local.environment.json @@ -0,0 +1,8 @@ +{ + "environment": [ + { + "env": "local", + "paymentOptionsServiceURIBasePath": "http://localhost:8080" // TODO + } + ] +} diff --git a/perfomance-test/src/modules/payment_options_client.js b/perfomance-test/src/modules/payment_options_client.js new file mode 100644 index 0000000..39aec8b --- /dev/null +++ b/perfomance-test/src/modules/payment_options_client.js @@ -0,0 +1,9 @@ +import http from 'k6/http'; + +const subKey = `${__ENV.OCP_APIM_SUBSCRIPTION_KEY}`; + +// TODO +export function fetchPaymentOptions(url, fiscalCode) { + + return http.get(url, { headers, responseType: "text"}); +} \ No newline at end of file diff --git a/perfomance-test/src/package.json b/perfomance-test/src/package.json new file mode 100644 index 0000000..864ce35 --- /dev/null +++ b/perfomance-test/src/package.json @@ -0,0 +1,8 @@ +{ + "type": "module", + "dependencies": { + "axios": "^0.27.2" + }, + "scripts" : { + } +} diff --git a/perfomance-test/src/payment_options_service_test.js b/perfomance-test/src/payment_options_service_test.js new file mode 100644 index 0000000..71be8c5 --- /dev/null +++ b/perfomance-test/src/payment_options_service_test.js @@ -0,0 +1,5 @@ +const paymentOptionsServiceURIBasePath = `${ENV_VARS.paymentOptionsServiceURIBasePath}`; + +export default function () { + // TODO +} \ No newline at end of file diff --git a/perfomance-test/src/test-types/constant.json b/perfomance-test/src/test-types/constant.json new file mode 100644 index 0000000..242fafb --- /dev/null +++ b/perfomance-test/src/test-types/constant.json @@ -0,0 +1,50 @@ +{ + "discardResponseBodies": true, + "summaryTrendStats": [ + "avg", + "min", + "med", + "max", + "p(95)", + "p(99)", + "p(99.99)", + "count" + ], + "scenarios": { + "contacts": { + "executor": "constant-arrival-rate", + "duration": "5m", + "rate": 75, + "timeUnit": "1s", + "preAllocatedVUs": 100, + "maxVUs": 200 + } + }, + "thresholds": { + "http_req_failed": [ + "rate<0.1" + ], + "http_req_duration": [ + "p(99)<2000" + ], + "http_req_duration{group:::setup}": [ + "max>=0" + ], + "http_req_duration{scenario:contacts}": [ + "max>=0" + ], + "iteration_duration{scenario:contacts}": [ + "max>=0" + ], + "iteration_duration{group:::setup}": [ + "max>=0" + ], + "iterations{group:::setup}": [ + "rate>=0" + ], + "iterations{scenario:contacts}": [ + "rate>=0" + ] + }, + "setupTimeout": "60m" + } \ No newline at end of file diff --git a/perfomance-test/src/test-types/load.json b/perfomance-test/src/test-types/load.json new file mode 100644 index 0000000..1525a1a --- /dev/null +++ b/perfomance-test/src/test-types/load.json @@ -0,0 +1,34 @@ +{ + "summaryTrendStats": [ + "avg", + "min", + "med", + "max", + "p(95)", + "p(99)", + "p(99.99)", + "count" + ], + "stages": [ + { + "duration": "1m", + "target": 20 + }, + { + "duration": "2m", + "target": 20 + }, + { + "duration": "2m", + "target": 0 + } + ], + "thresholds": { + "http_req_failed": [ + "rate<0.001" + ], + "http_req_duration": [ + "p(99)<1500" + ] + } +} diff --git a/perfomance-test/src/test-types/spike.json b/perfomance-test/src/test-types/spike.json new file mode 100644 index 0000000..efbf1d4 --- /dev/null +++ b/perfomance-test/src/test-types/spike.json @@ -0,0 +1,38 @@ +{ + "summaryTrendStats": [ + "avg", + "min", + "med", + "max", + "p(95)", + "p(99)", + "p(99.99)", + "count" + ], + "stages": [ + { + "duration": "10s", + "target": 1 + }, + { + "duration": "20s", + "target": 5 + }, + { + "duration": "10s", + "target": 1 + }, + { + "duration": "10s", + "target": 0 + } + ], + "thresholds": { + "http_req_failed": [ + "rate<0.001" + ], + "http_req_duration": [ + "p(99)<100" + ] + } +} diff --git a/perfomance-test/src/test-types/stress.json b/perfomance-test/src/test-types/stress.json new file mode 100644 index 0000000..f9cf5d5 --- /dev/null +++ b/perfomance-test/src/test-types/stress.json @@ -0,0 +1,61 @@ +{ + "summaryTrendStats": [ + "avg", + "min", + "med", + "max", + "p(95)", + "p(99)", + "p(99.99)", + "count" + ], + "stages": [ + { + "duration": "2m", + "target": 100 + }, + { + "duration": "5m", + "target": 100 + }, + { + "duration": "2m", + "target": 200 + }, + { + "duration": "5m", + "target": 200 + }, + { + "duration": "2m", + "target": 300 + }, + { + "duration": "5m", + "target": 300 + }, + { + "duration": "2m", + "target": 400 + }, + { + "duration": "5m", + "target": 400 + }, + { + "duration": "10m", + "target": 0 + } + ], + "thresholds": { + "http_req_failed": [ + "rate<0.001" + ], + "http_req_duration": [ + "p(99)<5000" + ], + "http_req_duration{bizEventMethod:GetOrganizationReceipt}": [ + "p(95)<1500" + ] + } +} diff --git a/perfomance-test/src/uat.environment.json b/perfomance-test/src/uat.environment.json new file mode 100644 index 0000000..6f85ee9 --- /dev/null +++ b/perfomance-test/src/uat.environment.json @@ -0,0 +1,8 @@ +{ + "environment": [ + { + "env": "uat", + "paymentOptionsServiceURIBasePath": "https://api.uat.platform.pagopa.it/payment-options/v1" // TODO + } + ] +} From 92507eb4f95c4c30eaec3db7bdc3296eec3f5f9b Mon Sep 17 00:00:00 2001 From: svariant Date: Fri, 27 Sep 2024 12:09:16 +0200 Subject: [PATCH 2/5] [PPANTT-73] feat: Complete performance test --- .devops/performance-test-pipelines.yml | 17 +++++--- perfomance-test/src/dev.environment.json | 2 +- perfomance-test/src/local.environment.json | 2 +- .../src/modules/payment_options_client.js | 10 +++-- .../src/payment_options_service_test.js | 43 ++++++++++++++++++- perfomance-test/src/uat.environment.json | 2 +- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/.devops/performance-test-pipelines.yml b/.devops/performance-test-pipelines.yml index 3b9bb84..3fc53be 100644 --- a/.devops/performance-test-pipelines.yml +++ b/.devops/performance-test-pipelines.yml @@ -18,12 +18,16 @@ parameters: - "stress" - "constant" default: "constant" - - name: "SCRIPT" - displayName: "Script name" + - name: "NOTICE_TYPE" + displayName: "Notice type" type: string values: - - "payment_options_service_test" - default: "payment_options_service_test" + - "single_opt" + - "single_and_many_opt" + - "single_and_multy_opt" + - "single_and_co_opt" + - "all" + default: "all" - name: "DB_NAME" displayName: "DB name" type: string @@ -47,8 +51,9 @@ steps: displayName: Pull k6 image - script: | cd ./performance-test - sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} ${{ parameters.SCRIPT }} ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY - displayName: Run k6 ${{ parameters.SCRIPT }} on ${{ parameters.ENVIRONMENT }} + sh ./run_performance_test.sh ${{ parameters.ENVIRONMENT }} ${{ parameters.TEST_TYPE }} payment_options_service_test ${{ parameters.DB_NAME}} $OCP_APIM_SUBSCRIPTION_KEY + displayName: Run k6 payment_options_service_test with notice type ${{ parameters.NOTICE_TYPE}} on ${{ parameters.ENVIRONMENT }} env: OCP_APIM_SUBSCRIPTION_KEY: ${{ variables.API_SUBSCRIPTION_KEY }} + NOTICE_TYPE: ${{ parameters.NOTICE_TYPE }} diff --git a/perfomance-test/src/dev.environment.json b/perfomance-test/src/dev.environment.json index 97692f8..ba2b627 100644 --- a/perfomance-test/src/dev.environment.json +++ b/perfomance-test/src/dev.environment.json @@ -2,7 +2,7 @@ "environment": [ { "env": "dev", - "paymentOptionsServiceURIBasePath": "https://api.dev.platform.pagopa.it/payment-options/v1" // TODO + "paymentOptionsServiceURIBasePath": "https://api.dev.platform.pagopa.it/payment-options/service/v1" } ] } diff --git a/perfomance-test/src/local.environment.json b/perfomance-test/src/local.environment.json index 4e44e80..6f50451 100644 --- a/perfomance-test/src/local.environment.json +++ b/perfomance-test/src/local.environment.json @@ -2,7 +2,7 @@ "environment": [ { "env": "local", - "paymentOptionsServiceURIBasePath": "http://localhost:8080" // TODO + "paymentOptionsServiceURIBasePath": "http://localhost:8080" } ] } diff --git a/perfomance-test/src/modules/payment_options_client.js b/perfomance-test/src/modules/payment_options_client.js index 39aec8b..45db7fb 100644 --- a/perfomance-test/src/modules/payment_options_client.js +++ b/perfomance-test/src/modules/payment_options_client.js @@ -2,8 +2,12 @@ import http from 'k6/http'; const subKey = `${__ENV.OCP_APIM_SUBSCRIPTION_KEY}`; -// TODO -export function fetchPaymentOptions(url, fiscalCode) { +export function getToService(url, params) { - return http.get(url, { headers, responseType: "text"}); + let headers = { + 'Ocp-Apim-Subscription-Key': subKey, + "Content-Type": "application/json" + }; + + return http.get(url, { headers, responseType: "text", params }); } \ No newline at end of file diff --git a/perfomance-test/src/payment_options_service_test.js b/perfomance-test/src/payment_options_service_test.js index 71be8c5..76cdb91 100644 --- a/perfomance-test/src/payment_options_service_test.js +++ b/perfomance-test/src/payment_options_service_test.js @@ -1,5 +1,46 @@ +import { getToService } from "./modules/payment_options_client"; + const paymentOptionsServiceURIBasePath = `${ENV_VARS.paymentOptionsServiceURIBasePath}`; +const noticeType = `${__ENV.NOTICE_TYPE}`; + +const ORGANIZATIONAL_FISCAL_CODE = "77777777777"; + +const SINGLE_OPT_NOTICE_NUMBER = "311111111111111111"; +const SINGLE_AND_MANY_OPT_NOTICE_NUMBER = "311111111111111112"; +const SINGLE_AND_MULTI_OPT_NOTICE_NUMBER = "311111111111111116"; +const SINGLE_AND_CO_OPT_NOTICE_NUMBER = "311111111112222225"; + +const VALID_PSP = "99999000001"; + +const getSelectedNoticeNumbers = () => { + const selectedNotices = []; + if (noticeType === "single_opt" || noticeType === "all") { + selectedNotices.push(SINGLE_OPT_NOTICE_NUMBER); + } + if (noticeType === "single_and_many_opt" || noticeType === "all") { + selectedNotices.push(SINGLE_AND_MANY_OPT_NOTICE_NUMBER); + } + if (noticeType === "single_and_multy_opt" || noticeType === "all") { + selectedNotices.push(SINGLE_AND_MULTI_OPT_NOTICE_NUMBER); + } + if (noticeType === "single_and_co_opt" || noticeType === "all") { + selectedNotices.push(SINGLE_AND_CO_OPT_NOTICE_NUMBER); + } + return selectedNotices; +} export default function () { - // TODO + getSelectedNoticeNumbers().forEach(el => { + let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${SINGLE_OPT_NOTICE_NUMBER}`, {idPsp: VALID_PSP}); + console.info(`Payment Options Service getPaymentOptions with notice number ${el} call, Status ${response.status}`); + + let responseBody = JSON.parse(response.body); + + check(response, { + 'Payment Options Service getPaymentOptions status is 200': () => response.status === 200, + 'Payment Options Service getPaymentOptions body has list of payment options': () => + Boolean(responseBody?.paymentOptions?.length) + }); + }) + } \ No newline at end of file diff --git a/perfomance-test/src/uat.environment.json b/perfomance-test/src/uat.environment.json index 6f85ee9..2173e50 100644 --- a/perfomance-test/src/uat.environment.json +++ b/perfomance-test/src/uat.environment.json @@ -2,7 +2,7 @@ "environment": [ { "env": "uat", - "paymentOptionsServiceURIBasePath": "https://api.uat.platform.pagopa.it/payment-options/v1" // TODO + "paymentOptionsServiceURIBasePath": "https://api.uat.platform.pagopa.it/payment-options/service/v1" } ] } From 2f83d6d2bca27b89289e1b36d28f8c7488586d62 Mon Sep 17 00:00:00 2001 From: svariant Date: Fri, 27 Sep 2024 12:20:26 +0200 Subject: [PATCH 3/5] [PPANTT-73] fix: Rename performance folder --- {perfomance-test => performance-test}/README.md | 0 {perfomance-test => performance-test}/docker-compose.yaml | 0 {perfomance-test => performance-test}/nginx/nginx.conf | 0 {perfomance-test => performance-test}/run_performance_test.sh | 0 {perfomance-test => performance-test}/src/dev.environment.json | 0 {perfomance-test => performance-test}/src/local.environment.json | 0 .../src/modules/payment_options_client.js | 0 {perfomance-test => performance-test}/src/package.json | 0 .../src/payment_options_service_test.js | 1 + .../src/test-types/constant.json | 0 {perfomance-test => performance-test}/src/test-types/load.json | 0 {perfomance-test => performance-test}/src/test-types/spike.json | 0 {perfomance-test => performance-test}/src/test-types/stress.json | 0 {perfomance-test => performance-test}/src/uat.environment.json | 0 14 files changed, 1 insertion(+) rename {perfomance-test => performance-test}/README.md (100%) rename {perfomance-test => performance-test}/docker-compose.yaml (100%) rename {perfomance-test => performance-test}/nginx/nginx.conf (100%) rename {perfomance-test => performance-test}/run_performance_test.sh (100%) rename {perfomance-test => performance-test}/src/dev.environment.json (100%) rename {perfomance-test => performance-test}/src/local.environment.json (100%) rename {perfomance-test => performance-test}/src/modules/payment_options_client.js (100%) rename {perfomance-test => performance-test}/src/package.json (100%) rename {perfomance-test => performance-test}/src/payment_options_service_test.js (99%) rename {perfomance-test => performance-test}/src/test-types/constant.json (100%) rename {perfomance-test => performance-test}/src/test-types/load.json (100%) rename {perfomance-test => performance-test}/src/test-types/spike.json (100%) rename {perfomance-test => performance-test}/src/test-types/stress.json (100%) rename {perfomance-test => performance-test}/src/uat.environment.json (100%) diff --git a/perfomance-test/README.md b/performance-test/README.md similarity index 100% rename from perfomance-test/README.md rename to performance-test/README.md diff --git a/perfomance-test/docker-compose.yaml b/performance-test/docker-compose.yaml similarity index 100% rename from perfomance-test/docker-compose.yaml rename to performance-test/docker-compose.yaml diff --git a/perfomance-test/nginx/nginx.conf b/performance-test/nginx/nginx.conf similarity index 100% rename from perfomance-test/nginx/nginx.conf rename to performance-test/nginx/nginx.conf diff --git a/perfomance-test/run_performance_test.sh b/performance-test/run_performance_test.sh similarity index 100% rename from perfomance-test/run_performance_test.sh rename to performance-test/run_performance_test.sh diff --git a/perfomance-test/src/dev.environment.json b/performance-test/src/dev.environment.json similarity index 100% rename from perfomance-test/src/dev.environment.json rename to performance-test/src/dev.environment.json diff --git a/perfomance-test/src/local.environment.json b/performance-test/src/local.environment.json similarity index 100% rename from perfomance-test/src/local.environment.json rename to performance-test/src/local.environment.json diff --git a/perfomance-test/src/modules/payment_options_client.js b/performance-test/src/modules/payment_options_client.js similarity index 100% rename from perfomance-test/src/modules/payment_options_client.js rename to performance-test/src/modules/payment_options_client.js diff --git a/perfomance-test/src/package.json b/performance-test/src/package.json similarity index 100% rename from perfomance-test/src/package.json rename to performance-test/src/package.json diff --git a/perfomance-test/src/payment_options_service_test.js b/performance-test/src/payment_options_service_test.js similarity index 99% rename from perfomance-test/src/payment_options_service_test.js rename to performance-test/src/payment_options_service_test.js index 76cdb91..cb11d2d 100644 --- a/perfomance-test/src/payment_options_service_test.js +++ b/performance-test/src/payment_options_service_test.js @@ -13,6 +13,7 @@ const SINGLE_AND_CO_OPT_NOTICE_NUMBER = "311111111112222225"; const VALID_PSP = "99999000001"; const getSelectedNoticeNumbers = () => { + const selectedNotices = []; if (noticeType === "single_opt" || noticeType === "all") { selectedNotices.push(SINGLE_OPT_NOTICE_NUMBER); diff --git a/perfomance-test/src/test-types/constant.json b/performance-test/src/test-types/constant.json similarity index 100% rename from perfomance-test/src/test-types/constant.json rename to performance-test/src/test-types/constant.json diff --git a/perfomance-test/src/test-types/load.json b/performance-test/src/test-types/load.json similarity index 100% rename from perfomance-test/src/test-types/load.json rename to performance-test/src/test-types/load.json diff --git a/perfomance-test/src/test-types/spike.json b/performance-test/src/test-types/spike.json similarity index 100% rename from perfomance-test/src/test-types/spike.json rename to performance-test/src/test-types/spike.json diff --git a/perfomance-test/src/test-types/stress.json b/performance-test/src/test-types/stress.json similarity index 100% rename from perfomance-test/src/test-types/stress.json rename to performance-test/src/test-types/stress.json diff --git a/perfomance-test/src/uat.environment.json b/performance-test/src/uat.environment.json similarity index 100% rename from perfomance-test/src/uat.environment.json rename to performance-test/src/uat.environment.json From 1129f875d13a5f1414dde3ad7c247c5b2dc4ba5e Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 30 Sep 2024 11:37:13 +0200 Subject: [PATCH 4/5] [PPANTT-73] feat: Fix performance tests notice undefined & queryParams --- .../src/modules/payment_options_client.js | 12 ++++++-- .../src/payment_options_service_test.js | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/performance-test/src/modules/payment_options_client.js b/performance-test/src/modules/payment_options_client.js index 45db7fb..608a19b 100644 --- a/performance-test/src/modules/payment_options_client.js +++ b/performance-test/src/modules/payment_options_client.js @@ -1,13 +1,19 @@ import http from 'k6/http'; - const subKey = `${__ENV.OCP_APIM_SUBSCRIPTION_KEY}`; -export function getToService(url, params) { - +export function getToService(endpoint, params) { + let url = endpoint; let headers = { 'Ocp-Apim-Subscription-Key': subKey, "Content-Type": "application/json" }; + const queryParams = params ? Object.entries(params) : []; + if (queryParams?.length) { + queryParams.forEach((el, index) => { + url = url.concat(index === 0 ? "?" : "&", el[0], "=", el[1]); + }); + } + return http.get(url, { headers, responseType: "text", params }); } \ No newline at end of file diff --git a/performance-test/src/payment_options_service_test.js b/performance-test/src/payment_options_service_test.js index cb11d2d..42fdb11 100644 --- a/performance-test/src/payment_options_service_test.js +++ b/performance-test/src/payment_options_service_test.js @@ -1,4 +1,11 @@ -import { getToService } from "./modules/payment_options_client"; +import { getToService } from "./modules/payment_options_client.js"; +import { SharedArray } from 'k6/data'; +import { check } from 'k6'; + +const varsArray = new SharedArray('vars', function () { + return JSON.parse(open(`./${__ENV.VARS}`)).environment; +}); +export const ENV_VARS = varsArray[0]; const paymentOptionsServiceURIBasePath = `${ENV_VARS.paymentOptionsServiceURIBasePath}`; const noticeType = `${__ENV.NOTICE_TYPE}`; @@ -13,26 +20,30 @@ const SINGLE_AND_CO_OPT_NOTICE_NUMBER = "311111111112222225"; const VALID_PSP = "99999000001"; const getSelectedNoticeNumbers = () => { - + const noticeTypeAll = noticeType === "undefined" || noticeType === "all"; + const selectedNotices = []; - if (noticeType === "single_opt" || noticeType === "all") { + if (noticeType === "single_opt" || noticeTypeAll) { selectedNotices.push(SINGLE_OPT_NOTICE_NUMBER); } - if (noticeType === "single_and_many_opt" || noticeType === "all") { + if (noticeType === "single_and_many_opt" || noticeTypeAll) { selectedNotices.push(SINGLE_AND_MANY_OPT_NOTICE_NUMBER); } - if (noticeType === "single_and_multy_opt" || noticeType === "all") { + if (noticeType === "single_and_multy_opt" || noticeTypeAll) { selectedNotices.push(SINGLE_AND_MULTI_OPT_NOTICE_NUMBER); } - if (noticeType === "single_and_co_opt" || noticeType === "all") { + if (noticeType === "single_and_co_opt" || noticeTypeAll) { selectedNotices.push(SINGLE_AND_CO_OPT_NOTICE_NUMBER); } + console.log(`Selected the following notices: ${JSON.stringify(selectedNotices)}`); return selectedNotices; } export default function () { - getSelectedNoticeNumbers().forEach(el => { - let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${SINGLE_OPT_NOTICE_NUMBER}`, {idPsp: VALID_PSP}); + const selectedNotices = getSelectedNoticeNumbers(); + for (let i = 0; i < selectedNotices.length; i++) { + const el = selectedNotices[i]; + let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${SINGLE_OPT_NOTICE_NUMBER}`, { idPsp: VALID_PSP }); console.info(`Payment Options Service getPaymentOptions with notice number ${el} call, Status ${response.status}`); let responseBody = JSON.parse(response.body); @@ -42,6 +53,5 @@ export default function () { 'Payment Options Service getPaymentOptions body has list of payment options': () => Boolean(responseBody?.paymentOptions?.length) }); - }) - + } } \ No newline at end of file From 91e9d2b83bc9433c61fe00037dd3ed981c996850 Mon Sep 17 00:00:00 2001 From: svariant Date: Mon, 30 Sep 2024 11:59:51 +0200 Subject: [PATCH 5/5] [PPANTT-73] fix: Optional chaining not supported by k6 --- performance-test/src/modules/payment_options_client.js | 2 +- performance-test/src/payment_options_service_test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/performance-test/src/modules/payment_options_client.js b/performance-test/src/modules/payment_options_client.js index 608a19b..5fa31ac 100644 --- a/performance-test/src/modules/payment_options_client.js +++ b/performance-test/src/modules/payment_options_client.js @@ -9,7 +9,7 @@ export function getToService(endpoint, params) { }; const queryParams = params ? Object.entries(params) : []; - if (queryParams?.length) { + if (queryParams && queryParams.length) { queryParams.forEach((el, index) => { url = url.concat(index === 0 ? "?" : "&", el[0], "=", el[1]); }); diff --git a/performance-test/src/payment_options_service_test.js b/performance-test/src/payment_options_service_test.js index 42fdb11..135e31a 100644 --- a/performance-test/src/payment_options_service_test.js +++ b/performance-test/src/payment_options_service_test.js @@ -43,7 +43,7 @@ export default function () { const selectedNotices = getSelectedNoticeNumbers(); for (let i = 0; i < selectedNotices.length; i++) { const el = selectedNotices[i]; - let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${SINGLE_OPT_NOTICE_NUMBER}`, { idPsp: VALID_PSP }); + let response = getToService(`${paymentOptionsServiceURIBasePath}/payment-options/organizations/${ORGANIZATIONAL_FISCAL_CODE}/notices/${el}`, { idPsp: VALID_PSP }); console.info(`Payment Options Service getPaymentOptions with notice number ${el} call, Status ${response.status}`); let responseBody = JSON.parse(response.body); @@ -51,7 +51,7 @@ export default function () { check(response, { 'Payment Options Service getPaymentOptions status is 200': () => response.status === 200, 'Payment Options Service getPaymentOptions body has list of payment options': () => - Boolean(responseBody?.paymentOptions?.length) + Boolean(responseBody && responseBody.paymentOptions && responseBody.paymentOptions.length) }); } } \ No newline at end of file