Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 446 additions & 0 deletions k6-tests/all-services-test.js

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions k6-tests/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Shared configuration for all K6 performance test scripts.
*
* Environment variables (pass via -e flag or __ENV):
* BASE_URL – API Gateway root (default http://localhost:5000)
* AUTH_USERNAME – Basic-auth username (default "admin")
* AUTH_PASSWORD – Basic-auth password (default "password")
* AUTH_TOKEN_URL – OAuth / token endpoint for Bearer auth
* AUTH_CLIENT_ID – OAuth client id
* AUTH_CLIENT_SECRET – OAuth client secret
* VUS – override default virtual users
* DURATION – override default duration
*/

// ---------------------------------------------------------------------------
// Service base URLs – routed through the API Gateway (port 5000) by default.
// Override with direct service URLs when testing individual services.
// ---------------------------------------------------------------------------
export const BASE_URL = __ENV.BASE_URL || 'http://localhost:5000';
export const IDENTITY_URL = __ENV.IDENTITY_URL || `${BASE_URL}/api/identity`;
export const CUSTOMER_URL = __ENV.CUSTOMER_URL || `${BASE_URL}/api/customer`;
export const ORDER_URL = __ENV.ORDER_URL || `${BASE_URL}/api/order`;
export const PRODUCT_URL = __ENV.PRODUCT_URL || `${BASE_URL}/api/product`;
export const NOTIFICATION_URL = __ENV.NOTIFICATION_URL || `${BASE_URL}/api/notification`;

// ---------------------------------------------------------------------------
// Authentication
// ---------------------------------------------------------------------------
export const AUTH_USERNAME = __ENV.AUTH_USERNAME || 'admin';
export const AUTH_PASSWORD = __ENV.AUTH_PASSWORD || 'password';
export const AUTH_TOKEN_URL = __ENV.AUTH_TOKEN_URL || `${BASE_URL}/api/identity/token`;
export const AUTH_CLIENT_ID = __ENV.AUTH_CLIENT_ID || '';
export const AUTH_CLIENT_SECRET = __ENV.AUTH_CLIENT_SECRET || '';

// ---------------------------------------------------------------------------
// Default load-test options (can be imported and merged per-script)
// ---------------------------------------------------------------------------
export const DEFAULT_STAGES = [
{ duration: '30s', target: 10 }, // ramp-up
{ duration: '1m', target: 10 }, // steady state
{ duration: '30s', target: 20 }, // spike
{ duration: '1m', target: 20 }, // sustained spike
{ duration: '30s', target: 0 }, // ramp-down
];

export const DEFAULT_THRESHOLDS = {
http_req_duration: ['p(95)<500', 'p(99)<1000'], // 95th < 500 ms, 99th < 1 s
http_req_failed: ['rate<0.05'], // < 5 % error rate
checks: ['rate>0.95'], // > 95 % of checks pass
};

export const DEFAULT_OPTIONS = {
stages: DEFAULT_STAGES,
thresholds: DEFAULT_THRESHOLDS,
noConnectionReuse: false,
userAgent: 'K6-PerformanceTest/1.0',
};
97 changes: 97 additions & 0 deletions k6-tests/customer-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* K6 Performance Test — Customer Service
*
* Endpoints tested:
* GET /api/customer — List all customers
* GET /api/customer/{id} — Get customer by ID
*
* Run:
* k6 run customer-test.js
* k6 run -e BASE_URL=http://localhost:5002 customer-test.js
*/
import http from 'k6/http';
import { check, group } from 'k6';
import { SharedArray } from 'k6/data';
import { CUSTOMER_URL, DEFAULT_THRESHOLDS, DEFAULT_STAGES } from './config.js';
import { jsonHeaders, basicAuthHeaders, fetchBearerToken, checkGetResponse } from './utils.js';

// ---------------------------------------------------------------------------
// Data-driven testing — load customer test data via SharedArray
// ---------------------------------------------------------------------------
const customers = new SharedArray('customers', function () {
return JSON.parse(open('./data/customers.json'));
});

// ---------------------------------------------------------------------------
// Options
// ---------------------------------------------------------------------------
export const options = {
stages: DEFAULT_STAGES,
thresholds: {
...DEFAULT_THRESHOLDS,
'http_req_duration{group:::Customer - Get All}': ['p(95)<400'],
'http_req_duration{group:::Customer - Get By ID}': ['p(95)<300'],
},
tags: { service: 'customer' },
};

// ---------------------------------------------------------------------------
// Setup — authenticate and return a token for use in default function
// ---------------------------------------------------------------------------
export function setup() {
const token = fetchBearerToken();
return { token };
}

// ---------------------------------------------------------------------------
// Default (main) function — executed by each VU on every iteration
// ---------------------------------------------------------------------------
export default function (data) {
const headers = data.token
? jsonHeaders(data.token)
: basicAuthHeaders();

// ---- Group 1: Get All Customers ----
group('Customer - Get All', function () {
const res = http.get(CUSTOMER_URL, {
headers,
tags: { name: 'GET /api/customer' },
});

checkGetResponse(res, 'Get All Customers');

check(res, {
'response is JSON': (r) => {
try {
JSON.parse(r.body);
return true;
} catch (_) {
return false;
}
},
});
});

// ---- Group 2: Get Customer By ID (data-driven) ----
group('Customer - Get By ID', function () {
const customer = customers[Math.floor(Math.random() * customers.length)];

const res = http.get(`${CUSTOMER_URL}/${customer.id}`, {
headers,
tags: { name: 'GET /api/customer/{id}' },
});

checkGetResponse(res, `Get Customer ${customer.id}`);

check(res, {
'response contains id field': (r) => {
try {
const body = JSON.parse(r.body);
return body.id !== undefined;
} catch (_) {
return false;
}
},
});
});
}
22 changes: 22 additions & 0 deletions k6-tests/data/customers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{ "id": 1, "name": "Alice Johnson", "email": "alice.j@techstart.io", "phone": "555-0101", "tier": "Gold" },
{ "id": 2, "name": "Bob Martinez", "email": "bob.m@retailhub.com", "phone": "555-0102", "tier": "Silver" },
{ "id": 3, "name": "Carol Lee", "email": "carol.lee@freshmkt.com", "phone": "555-0103", "tier": "Bronze" },
{ "id": 4, "name": "David Kim", "email": "david.kim@luxbrand.co", "phone": "555-0104", "tier": "Gold" },
{ "id": 5, "name": "Eva Brown", "email": "eva.brown@ecogoods.io", "phone": "555-0105", "tier": "Silver" },
{ "id": 6, "name": "Frank Nguyen", "email": "frank.n@quickship.com", "phone": "555-0106", "tier": "Bronze" },
{ "id": 7, "name": "Grace Okafor", "email": "grace.o@artisan.shop", "phone": "555-0107", "tier": "Gold" },
{ "id": 8, "name": "Hector Ruiz", "email": "hector.r@sportzone.com", "phone": "555-0108", "tier": "Silver" },
{ "id": 9, "name": "Irene Sato", "email": "irene.s@bookworm.co", "phone": "555-0109", "tier": "Bronze" },
{ "id": 10, "name": "James Patel", "email": "james.p@gadgetworld.io", "phone": "555-0110", "tier": "Gold" },
{ "id": 11, "name": "Katya Volkov", "email": "katya.v@homegoods.com", "phone": "555-0111", "tier": "Silver" },
{ "id": 12, "name": "Leo Chen", "email": "leo.c@petcorner.shop", "phone": "555-0112", "tier": "Bronze" },
{ "id": 13, "name": "Maria Fernandez", "email": "maria.f@stylehub.com", "phone": "555-0113", "tier": "Gold" },
{ "id": 14, "name": "Nils Eriksson", "email": "nils.e@outdooradv.io", "phone": "555-0114", "tier": "Silver" },
{ "id": 15, "name": "Olivia Thompson", "email": "olivia.t@gourmet.co", "phone": "555-0115", "tier": "Bronze" },
{ "id": 16, "name": "Priya Sharma", "email": "priya.s@wellness.io", "phone": "555-0116", "tier": "Gold" },
{ "id": 17, "name": "Quinn Murphy", "email": "quinn.m@smartliving.com", "phone": "555-0117", "tier": "Silver" },
{ "id": 18, "name": "Raj Deshmukh", "email": "raj.d@craftbrew.co", "phone": "555-0118", "tier": "Bronze" },
{ "id": 19, "name": "Sofia Andersson", "email": "sofia.a@greenliving.io", "phone": "555-0119", "tier": "Gold" },
{ "id": 20, "name": "Tariq Hassan", "email": "tariq.h@fitgear.com", "phone": "555-0120", "tier": "Silver" }
]
22 changes: 22 additions & 0 deletions k6-tests/data/identities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{ "id": 1, "username": "admin", "email": "admin@globex.com", "role": "Admin" },
{ "id": 2, "username": "jdoe", "email": "john.doe@acmecorp.com", "role": "User" },
{ "id": 3, "username": "asmith", "email": "anna.smith@initech.com", "role": "User" },
{ "id": 4, "username": "mjones", "email": "mike.jones@wayneent.com", "role": "Manager" },
{ "id": 5, "username": "bwilson", "email": "beth.wilson@stark.io", "role": "User" },
{ "id": 6, "username": "cgarcia", "email": "carlos.garcia@hooli.com", "role": "User" },
{ "id": 7, "username": "dtran", "email": "diana.tran@piedpiper.io", "role": "Manager" },
{ "id": 8, "username": "ewright", "email": "eli.wright@umbrella.co", "role": "User" },
{ "id": 9, "username": "fmorales", "email": "fiona.morales@oscorp.com","role": "User" },
{ "id": 10, "username": "gkowalski", "email": "greg.kowalski@lexcorp.io","role": "Admin" },
{ "id": 11, "username": "hpatel", "email": "hina.patel@cyberdyne.ai", "role": "User" },
{ "id": 12, "username": "iokoro", "email": "izu.okoro@weyland.com", "role": "User" },
{ "id": 13, "username": "jpark", "email": "jin.park@aperture.sci", "role": "Manager" },
{ "id": 14, "username": "klindgren", "email": "karin.lindgren@abstergo.net", "role": "User" },
{ "id": 15, "username": "lchang", "email": "leon.chang@massiveD.com", "role": "User" },
{ "id": 16, "username": "mnguyen", "email": "mai.nguyen@vault-tec.io", "role": "User" },
{ "id": 17, "username": "obanerjee", "email": "om.banerjee@globex.com", "role": "Manager" },
{ "id": 18, "username": "pjohnson", "email": "paula.johnson@initech.com","role": "User" },
{ "id": 19, "username": "qali", "email": "qadir.ali@acmecorp.com", "role": "User" },
{ "id": 20, "username": "rstone", "email": "rachel.stone@wayneent.com","role": "Admin" }
]
122 changes: 122 additions & 0 deletions k6-tests/data/notifications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
[
{
"orderId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"customerId": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"totalAmount": 199.99,
"placedAt": "2026-04-30T08:12:33Z"
},
{
"orderId": "c3d4e5f6-a7b8-9012-cdef-123456789012",
"customerId": "d4e5f6a7-b8c9-0123-defa-234567890123",
"totalAmount": 59.98,
"placedAt": "2026-04-30T09:05:17Z"
},
{
"orderId": "e5f6a7b8-c9d0-1234-efab-345678901234",
"customerId": "f6a7b8c9-d0e1-2345-fabc-456789012345",
"totalAmount": 349.00,
"placedAt": "2026-04-30T09:45:02Z"
},
{
"orderId": "a7b8c9d0-e1f2-3456-abcd-567890123456",
"customerId": "b8c9d0e1-f2a3-4567-bcde-678901234567",
"totalAmount": 74.97,
"placedAt": "2026-04-30T10:22:41Z"
},
{
"orderId": "c9d0e1f2-a3b4-5678-cdef-789012345678",
"customerId": "d0e1f2a3-b4c5-6789-defa-890123456789",
"totalAmount": 29.99,
"placedAt": "2026-04-30T10:58:09Z"
},
{
"orderId": "11223344-5566-7788-99aa-bbccddeeff00",
"customerId": "aabbccdd-eeff-0011-2233-445566778899",
"totalAmount": 119.96,
"placedAt": "2026-04-30T11:15:55Z"
},
{
"orderId": "22334455-6677-8899-aabb-ccddeeff0011",
"customerId": "bbccddee-ff00-1122-3344-556677889900",
"totalAmount": 89.99,
"placedAt": "2026-04-30T11:33:28Z"
},
{
"orderId": "33445566-7788-99aa-bbcc-ddeeff001122",
"customerId": "ccddeeff-0011-2233-4455-667788990011",
"totalAmount": 99.98,
"placedAt": "2026-04-30T12:01:44Z"
},
{
"orderId": "44556677-8899-aabb-ccdd-eeff00112233",
"customerId": "ddeeff00-1122-3344-5566-778899001122",
"totalAmount": 599.99,
"placedAt": "2026-04-30T12:47:19Z"
},
{
"orderId": "55667788-99aa-bbcc-ddee-ff0011223344",
"customerId": "eeff0011-2233-4455-6677-889900112233",
"totalAmount": 149.95,
"placedAt": "2026-04-30T13:10:07Z"
},
{
"orderId": "66778899-aabb-ccdd-eeff-001122334455",
"customerId": "ff001122-3344-5566-7788-990011223344",
"totalAmount": 139.98,
"placedAt": "2026-04-30T13:35:52Z"
},
{
"orderId": "778899aa-bbcc-ddee-ff00-112233445566",
"customerId": "00112233-4455-6677-8899-aabbccddeeff",
"totalAmount": 249.99,
"placedAt": "2026-04-30T14:02:31Z"
},
{
"orderId": "8899aabb-ccdd-eeff-0011-223344556677",
"customerId": "11223344-5566-7788-99aa-bbccddeeff00",
"totalAmount": 44.97,
"placedAt": "2026-04-30T14:28:16Z"
},
{
"orderId": "99aabbcc-ddee-ff00-1122-334455667788",
"customerId": "22334455-6677-8899-aabb-ccddeeff0011",
"totalAmount": 179.99,
"placedAt": "2026-04-30T14:55:03Z"
},
{
"orderId": "aabbccdd-eeff-0011-2233-445566778899",
"customerId": "33445566-7788-99aa-bbcc-ddeeff001122",
"totalAmount": 69.98,
"placedAt": "2026-04-30T15:11:48Z"
},
{
"orderId": "bbccddee-ff00-1122-3344-556677889900",
"customerId": "44556677-8899-aabb-ccdd-eeff00112233",
"totalAmount": 449.99,
"placedAt": "2026-04-30T15:40:22Z"
},
{
"orderId": "ccddeeff-0011-2233-4455-667788990011",
"customerId": "55667788-99aa-bbcc-ddee-ff0011223344",
"totalAmount": 53.94,
"placedAt": "2026-04-30T16:05:37Z"
},
{
"orderId": "ddeeff00-1122-3344-5566-778899001122",
"customerId": "66778899-aabb-ccdd-eeff-001122334455",
"totalAmount": 999.99,
"placedAt": "2026-04-30T16:33:14Z"
},
{
"orderId": "eeff0011-2233-4455-6677-889900112233",
"customerId": "778899aa-bbcc-ddee-ff00-112233445566",
"totalAmount": 159.98,
"placedAt": "2026-04-30T17:01:59Z"
},
{
"orderId": "ff001122-3344-5566-7788-990011223344",
"customerId": "8899aabb-ccdd-eeff-0011-223344556677",
"totalAmount": 39.99,
"placedAt": "2026-04-30T17:28:46Z"
}
]
22 changes: 22 additions & 0 deletions k6-tests/data/orders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{ "id": 1, "customerId": 1, "productId": 3, "quantity": 1, "totalAmount": 199.99 },
{ "id": 2, "customerId": 5, "productId": 1, "quantity": 2, "totalAmount": 59.98 },
{ "id": 3, "customerId": 3, "productId": 7, "quantity": 1, "totalAmount": 349.00 },
{ "id": 4, "customerId": 10, "productId": 2, "quantity": 3, "totalAmount": 74.97 },
{ "id": 5, "customerId": 7, "productId": 5, "quantity": 1, "totalAmount": 29.99 },
{ "id": 6, "customerId": 12, "productId": 9, "quantity": 4, "totalAmount": 119.96 },
{ "id": 7, "customerId": 2, "productId": 12, "quantity": 1, "totalAmount": 89.99 },
{ "id": 8, "customerId": 15, "productId": 4, "quantity": 2, "totalAmount": 99.98 },
{ "id": 9, "customerId": 8, "productId": 15, "quantity": 1, "totalAmount": 599.99 },
{ "id": 10, "customerId": 19, "productId": 6, "quantity": 5, "totalAmount": 149.95 },
{ "id": 11, "customerId": 4, "productId": 11, "quantity": 2, "totalAmount": 139.98 },
{ "id": 12, "customerId": 16, "productId": 8, "quantity": 1, "totalAmount": 249.99 },
{ "id": 13, "customerId": 6, "productId": 14, "quantity": 3, "totalAmount": 44.97 },
{ "id": 14, "customerId": 14, "productId": 10, "quantity": 1, "totalAmount": 179.99 },
{ "id": 15, "customerId": 9, "productId": 13, "quantity": 2, "totalAmount": 69.98 },
{ "id": 16, "customerId": 20, "productId": 16, "quantity": 1, "totalAmount": 449.99 },
{ "id": 17, "customerId": 11, "productId": 18, "quantity": 6, "totalAmount": 53.94 },
{ "id": 18, "customerId": 13, "productId": 20, "quantity": 1, "totalAmount": 999.99 },
{ "id": 19, "customerId": 17, "productId": 17, "quantity": 2, "totalAmount": 159.98 },
{ "id": 20, "customerId": 18, "productId": 19, "quantity": 1, "totalAmount": 39.99 }
]
22 changes: 22 additions & 0 deletions k6-tests/data/products.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{ "id": 1, "name": "Wireless Mouse", "price": 29.99, "category": "Electronics", "sku": "ELEC-001" },
{ "id": 2, "name": "USB-C Hub", "price": 24.99, "category": "Electronics", "sku": "ELEC-002" },
{ "id": 3, "name": "Mechanical Keyboard", "price": 199.99, "category": "Electronics", "sku": "ELEC-003" },
{ "id": 4, "name": "Desk Lamp", "price": 49.99, "category": "Office", "sku": "OFFC-001" },
{ "id": 5, "name": "Notebook Pack", "price": 29.99, "category": "Office", "sku": "OFFC-002" },
{ "id": 6, "name": "Ergonomic Chair", "price": 349.00, "category": "Furniture", "sku": "FURN-001" },
{ "id": 7, "name": "Standing Desk", "price": 599.99, "category": "Furniture", "sku": "FURN-002" },
{ "id": 8, "name": "4K Monitor", "price": 249.99, "category": "Electronics", "sku": "ELEC-004" },
{ "id": 9, "name": "Noise-Cancel Headphones","price": 29.99, "category": "Audio", "sku": "AUDI-001" },
{ "id": 10, "name": "Bluetooth Speaker", "price": 179.99, "category": "Audio", "sku": "AUDI-002" },
{ "id": 11, "name": "Webcam HD", "price": 69.99, "category": "Electronics", "sku": "ELEC-005" },
{ "id": 12, "name": "External SSD 1TB", "price": 89.99, "category": "Storage", "sku": "STOR-001" },
{ "id": 13, "name": "Phone Stand", "price": 34.99, "category": "Accessories", "sku": "ACCS-001" },
{ "id": 14, "name": "Sticky Notes Bulk", "price": 14.99, "category": "Office", "sku": "OFFC-003" },
{ "id": 15, "name": "Ultrawide Monitor", "price": 599.99, "category": "Electronics", "sku": "ELEC-006" },
{ "id": 16, "name": "Laptop Backpack", "price": 449.99, "category": "Accessories", "sku": "ACCS-002" },
{ "id": 17, "name": "Wireless Charger", "price": 79.99, "category": "Electronics", "sku": "ELEC-007" },
{ "id": 18, "name": "Pens Multipack", "price": 8.99, "category": "Office", "sku": "OFFC-004" },
{ "id": 19, "name": "Cable Organizer", "price": 39.99, "category": "Accessories", "sku": "ACCS-003" },
{ "id": 20, "name": "Curved Gaming Monitor", "price": 999.99, "category": "Electronics", "sku": "ELEC-008" }
]
Loading