From e9aab0534747b39d7f1b641419481ded3d77a761 Mon Sep 17 00:00:00 2001 From: Sudip Bhattarai Date: Wed, 27 Nov 2024 16:35:28 +0545 Subject: [PATCH] Add load test script --- integration_test/load_test/ccv-flow.yml | 38 +++++++++++++ integration_test/load_test/flows.js | 40 ++++++++++++++ integration_test/load_test/package-lock.json | 56 ++++++++++++++++++++ integration_test/load_test/package.json | 10 ++++ 4 files changed, 144 insertions(+) create mode 100644 integration_test/load_test/ccv-flow.yml create mode 100644 integration_test/load_test/flows.js create mode 100644 integration_test/load_test/package-lock.json create mode 100644 integration_test/load_test/package.json diff --git a/integration_test/load_test/ccv-flow.yml b/integration_test/load_test/ccv-flow.yml new file mode 100644 index 0000000..1cbc84e --- /dev/null +++ b/integration_test/load_test/ccv-flow.yml @@ -0,0 +1,38 @@ +config: + # This is a test server run by team Artillery + # It's designed to be highly scalable + target: https://mainnet-ccv.cardanoapi.io + phases: + - duration: 20 + arrivalRate: 1 + rampTo: 5 + name: Warm up phase + - duration: 20 + arrivalRate: 5 + rampTo: 10 + name: Ramp up load + - duration: 30 + arrivalRate: 4 + rampTo: 30 + name: Spike phase + # Load & configure a couple of useful plugins + # https://docs.art/reference/extensions + plugins: + ensure: {} + apdex: {} + metrics-by-endpoint: {} + apdex: + threshold: 100 + ensure: + thresholds: + - http.response_time.p99: 500 + - http.response_time.p95: 400 + engines: + playwright: {} + # Path to JavaScript file that defines Playwright test functions + processor: './flows.js' +scenarios: + - engine: playwright + testFunction: visitPollFlow + - engine: playwright + testFunction: 'representativeFlow' diff --git a/integration_test/load_test/flows.js b/integration_test/load_test/flows.js new file mode 100644 index 0000000..33ed4ce --- /dev/null +++ b/integration_test/load_test/flows.js @@ -0,0 +1,40 @@ + +async function representativeFlow(page) { + // Navigate to the home page + await page.goto('/'); + await page.waitForLoadState('networkidle') + const randomX = Math.floor(Math.random() * 63)+1; + + // Navigate to the generated URL + await page.goto(`/representatives/${randomX}`); + await page.waitForLoadState('networkidle') + +} + +async function visitPollFlow(page) { + // Navigate to the home page + await page.goto('/'); + + await page.waitForLoadState('networkidle'); + + // List all cards with the data-testid attribute 'poll-card-xxx' + const pollCards = await page.$$('[data-testid^="poll-card-"]'); // Select all elements starting with 'poll-card-' + + if (pollCards.length === 0) { + console.log("No poll cards found!"); + return; + } + + // Select a random poll card + const randomIndex = Math.floor(Math.random() * pollCards.length); + const randomPollCard = pollCards[randomIndex]; + + // Click on the random card + await randomPollCard.click(); + await page.waitForLoadState('networkidle') + + // You can uncomment the next line if you need to navigate to a specific page after clicking + // await page.goto(`/representatives/${randomX}`); +} + +module.exports = { representativeFlow,visitPollFlow }; diff --git a/integration_test/load_test/package-lock.json b/integration_test/load_test/package-lock.json new file mode 100644 index 0000000..3f9c034 --- /dev/null +++ b/integration_test/load_test/package-lock.json @@ -0,0 +1,56 @@ +{ + "name": "load_testing", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "playwright": "^1.49.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.0.tgz", + "integrity": "sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==", + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.49.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.0.tgz", + "integrity": "sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==", + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + } + } +} diff --git a/integration_test/load_test/package.json b/integration_test/load_test/package.json new file mode 100644 index 0000000..023fec2 --- /dev/null +++ b/integration_test/load_test/package.json @@ -0,0 +1,10 @@ +{ + "scripts": { + "start": "artillery run --output result.json ccv-flow.yml ; artillery report result.json ", + "serve": "python3 -m http.server ", + "report": "artillery report result.json" + }, + "dependencies": { + "playwright": "^1.49.0" + } +}