Skip to content

Commit

Permalink
adding performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed Apr 6, 2024
1 parent 9a89772 commit 913ca4e
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Main Workflow
on: [push]
jobs:
build:
name: Run k6 test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run k6 local test
uses: grafana/[email protected]
with:
filename: tests/performance/tests/perf.js
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.vscode
.vscode
/tests/performance/node_modules
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestPaymentsAPI(t *testing.T) {
Currency: "AUD",
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
PaymentMethod: "credit",
Status: "success",
Status: "COMPLETED",
},
expected: http.StatusOK,
},
Expand Down
22 changes: 22 additions & 0 deletions tests/performance/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/performance/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "performance",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "k6 run tests/perf.js"
},
"author": "Dipjyoti Metia",
"license": "MIT",
"devDependencies": {
"@types/k6": "^0.50.0"
}
}
91 changes: 91 additions & 0 deletions tests/performance/tests/perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import http from 'k6/http';
import { check } from 'k6';

export const options = {
tags: {
test: 'api-performance',
test_run_id: `api-Load-Testing-${new Date().toISOString()}`,
},
thresholds: {
'http_req_failed{test_type:addExpense}': ['rate<0.01'], // http errors should be less than 1%, availability
'http_req_duration{test_type:addExpense}': ['p(95)<200'], // 95% of requests should be below 200ms, latency
'http_req_failed{test_type:addPayments}': ['rate<0.01'], // http errors should be less than 1%, availability
'http_req_duration{test_type:addPayments}': ['p(95)<200'], // 95% of requests should be below 200ms, latency
},
scenarios: {
// Load testing using K6 constant-rate scenario
addExpense_constant: {
executor: 'constant-arrival-rate',
rate: 10000, // number of iterations per time unit
timeUnit: '1m', // iterations will be per minute
duration: '1m', // total duration that the test will run for
preAllocatedVUs: 2, // the size of the VU (i.e. worker) pool for this scenario
maxVUs: 25, // if the preAllocatedVUs are not enough, we can initialize more
tags: { test_type: 'addExpense' }, // different extra metric tags for this scenario
exec: 'addExpense',// Test scenario function to call
},
addPayments_constant: {
executor: 'constant-arrival-rate',
rate: 10000, // number of iterations per time unit
timeUnit: '1m', // iterations will be per minute
duration: '1m', // total duration that the test will run for
preAllocatedVUs: 2, // the size of the VU (i.e. worker) pool for this scenario
maxVUs: 25, // if the preAllocatedVUs are not enough, we can initialize more
tags: { test_type: 'addPayments' }, // different extra metric tags for this scenario
exec: 'addPayments',// Test scenario function to call
}
}
};

export function addExpense() {
const url = 'http://localhost:8083/api/expense';

const payload = JSON.stringify({
expense_id: 'test',
user_id: '10010',
category: 'kafkaSync',
amount: 12.5,
currency: 'AUD',
timestamp: Date.now(),
description: 'Any',
receipt: 'newTest',
});

const params = {
headers: {
'Content-Type': 'application/json',
},
};

const response = http.post(url, payload, params);

check(response, {
'is status 200': (r) => r.status === 200,
});
}

export function addPayments() {
const url = 'http://localhost:8083/api/payment';

const payload = JSON.stringify({
transaction_id: 'test',
user_id: '10010',
amount: 12.5,
currency: 'AUD',
payment_method:'CREDIT_CARD',
timestamp: Date.now(),
status: 'COMPLETED',
});

const params = {
headers: {
'Content-Type': 'application/json',
},
};

const response = http.post(url, payload, params);

check(response, {
'is status 200': (r) => r.status === 200,
});
}

0 comments on commit 913ca4e

Please sign in to comment.