| name | load-testing |
| description | Create and manage K6 load tests for REST and GraphQL APIs. Use when creating load tests, writing K6 scripts, testing API performance, debugging load test failures, or setting up performance monitoring. Covers REST endpoints, GraphQL operations, data generation, IRI handling, configuration patterns, and performance troubleshooting. |
Load Testing Skill
Overview
This skill provides guidance for creating and managing K6 load tests for both REST and GraphQL APIs following VilnaCRM ecosystem patterns.
Core Principles
1. Individual Endpoint Testing
- Create separate test scripts for each endpoint (REST) or operation (GraphQL)
- Follow the pattern:
createResource.js, getResource.js, updateResource.js, deleteResource.js
- For GraphQL:
graphQLCreateResource.js, graphQLGetResource.js, etc.
- Avoid composite/random operation scripts for better debugging and clarity
2. Deterministic Testing
- NEVER use random operations in load tests
- Use predictable, iteration-based patterns (
__ITER % N)
- Ensure reproducible results for reliable performance analysis
3. Proper Resource Management
- Implement
setup() function to create test dependencies
- Implement
teardown() function to clean up test data
- Use proper IRI handling for REST APIs
- Use proper ID handling for GraphQL queries/mutations
4. Automatic Integration
- All test scripts are automatically discovered from
tests/Load/scripts/
- No separate commands needed - GraphQL and REST tests run together
- Use existing Makefile commands
Available Commands
make load-tests
make smoke-load-tests
make average-load-tests
make stress-load-tests
make spike-load-tests
make execute-load-tests-script scenario=createCustomer
make execute-load-tests-script scenario=graphQLCreateCustomer
./tests/Load/get-load-test-scenarios.sh
Quick Start Guide
1. Choose Test Type
- REST API: Use for HTTP endpoint testing
- GraphQL: Use for GraphQL query/mutation testing
2. Create Test Script
touch tests/Load/scripts/yourOperation.js
touch tests/Load/scripts/graphQLYourOperation.js
3. Follow Script Structure
See Supporting Files below for detailed templates and examples.
4. Add Configuration
Update tests/Load/config.json.dist with script parameters.
5. Test and Verify
make smoke-load-tests
Load Test Levels
| Level | VUs | Duration | Success Rate | Purpose |
|---|
| Smoke | 2-5 | 10 seconds | 100% | Basic functionality verification |
| Average | 10-20 | 2-3 minutes | >99% | Normal traffic simulation |
| Stress | 30-80 | 5-15 minutes | >95% | Find breaking points |
| Spike | 100-200 | 1-3 minutes | >90% | Test resilience under sudden load |
Common Pitfalls
❌ Don't Do This
const operation = Math.random();
const email = 'test@example.com';
✅ Do This Instead
const operationIndex = __ITER % 3;
const email = `test_${Date.now()}_${randomString(6)}@example.com`;
export function teardown(data) {
}
Checklist for New Load Tests
Before Creating
During Creation
After Creation
Performance Monitoring
Success Criteria
- Smoke Tests: 100% success rate
- Average Tests: >99% success rate
- Stress Tests: >95% success rate
- Response Times: <threshold configured per endpoint
Key Metrics
- HTTP status codes (201, 200, 204 for success)
- Response times (avg, p95, p99)
- Error rates and types
- Throughput (requests per second)
Supporting Files
For detailed patterns, examples, and reference documentation:
Quick Reference
REST API Test Structure
- Import required modules
- Create Utils and ScenarioUtils instances
- Export options from scenarioUtils
- Implement setup() for dependencies
- Implement default function for main test logic
- Implement teardown() for cleanup
- Use IRI format for resource references
GraphQL Test Structure
- Import required modules
- Create Utils and ScenarioUtils instances
- Export options from scenarioUtils
- Use REST API in setup() for faster dependency creation
- Use GraphQL in default function for actual testing
- Use REST API in teardown() for faster cleanup
- Handle full IRI format in queries/mutations
- Validate response.data and check for errors
This skill ensures consistent, professional, and effective load testing for both REST and GraphQL APIs across all VilnaCRM projects.