Skip to content

[Testing] Add k6 Load Testing Suite to Identify Performance Bottlenecks Under Stress - #40

Merged
KarenZita01 merged 4 commits into
EquipChain:mainfrom
Timrossid:feature/k6-load-testing
Jul 28, 2026
Merged

[Testing] Add k6 Load Testing Suite to Identify Performance Bottlenecks Under Stress#40
KarenZita01 merged 4 commits into
EquipChain:mainfrom
Timrossid:feature/k6-load-testing

Conversation

@Timrossid

Copy link
Copy Markdown

Summary

This PR introduces a comprehensive load testing suite using Grafana k6 to identify performance bottlenecks under stress for the EquipChain backend API. Five distinct test scenarios are implemented covering smoke, load, stress, spike, and soak testing patterns.

Closes #20


Changes Made

New API Endpoints (index.js)

  • GET /api/health — Health check endpoint returning server uptime, status, and timestamp
  • POST /api/auth/challenge — Mock wallet-based auth challenge returning a JWT token
  • GET /api/protected — Protected route requiring a Bearer token for access

k6 Load Testing Suite (k6/)

Test File VUs Duration Purpose
Smoke k6/smoke.js 1 VU 30s Verify basic functionality under zero load
Load k6/load.js 50 VUs 5min Simulate normal traffic (80% reads / 20% writes)
Stress k6/stress.js 10→500 VUs 5min+ Identify the API's breaking point
Spike k6/spike.js 0→200 VUs ~1.5min Test auto-scaling and connection handling
Soak k6/soak.js 50 VUs 30min+ Detect memory leaks and degradation over time

Shared Configuration (k6/shared.js)

  • Base URL parameterization via BASE_URL environment variable
  • Default headers and reusable thresholds
  • Helper functions: randomWallet(), randomInt(), thinkTime()

npm Scripts (package.json)

  • npm run k6:smoke — Run smoke test
  • npm run k6:load — Run load test
  • npm run k6:stress — Run stress test
  • npm run k6:spike — Run spike test
  • npm run k6:soak — Run soak test
  • npm run k6:quick — Run all tests except soak (which takes 30+ min)

Testing (test/server.test.js)

  • Added 6 new test cases covering all new endpoints
  • Tests for both success (200) and error (401) scenarios
  • All 7 tests passing

Documentation (README.md)

  • Complete k6 installation guide for macOS, Linux, and Windows
  • Detailed explanation of all test scenarios and their purposes
  • Configuration options and environment variable overrides
  • Metrics documentation (RPS, percentiles, error rates)
  • HTML report generation instructions
  • CI integration guidance

Configuration (.gitignore)

  • Ignore k6/results/* (generated reports) while preserving directory structure via .gitkeep

Verification

  • ✅ All 7 Node.js tests pass (npm test)
  • ✅ k6 smoke test passes with 0% error rate on valid requests
  • ✅ Response times within thresholds (p95 < 1000ms for smoke test)
  • ✅ Proper handling of expected 401 responses
  • ✅ All endpoints return correct data structures

How to Test

# Install k6
# https://k6.io/docs/get-started/installation/

# Start the server
npm start

# In a separate terminal, run any test
k6 run k6/smoke.js
k6 run k6/load.js
k6 run k6/stress.js
k6 run k6/spike.js

# Generate an HTML report
k6 run --out html=k6/results/report.html k6/smoke.js

@KarenZita01
KarenZita01 merged commit f8147a3 into EquipChain:main Jul 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Testing] Add Load Testing with k6 to Identify Performance Bottlenecks Under Stress

2 participants