Skip to content

zoroglucihat/load-testing-as-code

Repository files navigation

Load Testing as Code 🚀

Modern load testing framework using k6 with Infrastructure as Code principles. Manage your performance tests as code, version control them, and integrate with your CI/CD pipelines.

🔧 Installation

Prerequisites

  • Node.js 18+
  • k6 (can be installed with the commands below)

k6 Installation

macOS (Homebrew):

brew install k6

Linux:

sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6

Windows (Chocolatey):

choco install k6

Project Setup

npm install

🎯 Test Types

1. Smoke Test

Basic functionality check (low load, short duration):

npm run test

2. Load Test

Performance testing under normal load:

npm run test:load

3. Stress Test

Testing system limits and breaking points:

npm run test:stress

4. Spike Test

Testing sudden load increases:

npm run test:spike

5. API Test

Detailed API endpoint testing:

npm run test:api

6. Run All Tests

npm run test:all

📁 Project Structure

├── tests/
│   ├── smoke-test.js       # Smoke testing
│   ├── load-test.js        # Load testing
│   ├── stress-test.js      # Stress testing
│   ├── spike-test.js       # Spike testing
│   └── api-test.js         # API testing
├── utils/
│   ├── config.js           # Test configurations
│   ├── helpers.js          # Helper functions
│   └── data/               # Test data
├── scenarios/
│   ├── user-journey.js     # User scenarios
│   └── business-flows.js   # Business workflows
└── reports/                # Test reports

🔧 Configuration

Configure test parameters in utils/config.js:

  • Virtual Users (VUs): Number of concurrent users
  • Duration: Test duration
  • Thresholds: Success criteria
  • Base URL: Target system URL

📊 Monitoring & Dashboard

InfluxDB + Grafana Integration

# Save results to InfluxDB
npm run dashboard

Cloud Monitoring

For k6 Cloud integration:

k6 login cloud
k6 cloud tests/load-test.js

🚀 CI/CD Integration

GitHub Actions

Pipeline files are added to .github/workflows/ directory.

Jenkins Pipeline

Jenkins integration available via Jenkinsfile.

📈 Result Analysis

Test results are automatically saved to reports/ directory:

  • HTML reports
  • JSON metrics
  • Graphical representations

🛠️ Customization

To add your own tests:

  1. Add new JS file to tests/ directory
  2. Add npm script to package.json
  3. Add test scenarios to scenarios/ directory

📚 Best Practices

  • Start with smoke tests before running load tests
  • Use realistic test data for accurate results
  • Monitor system resources during tests
  • Set appropriate thresholds for your SLAs
  • Run tests in CI/CD for continuous performance validation

🔍 Test Patterns

Gradual Load Increase

stages: [
  { duration: '2m', target: 10 },
  { duration: '5m', target: 20 },
  { duration: '2m', target: 0 },
]

Spike Testing

stages: [
  { duration: '10s', target: 10 },
  { duration: '30s', target: 100 }, // Sudden spike
  { duration: '10s', target: 10 },
]

📞 Support

Feel free to open issues or check the documentation for questions.


Made with ❤️ for Performance Engineering

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published