This repository contains a K6-based stress test designed to test an API with authentication preconditions. It includes a Dockerized setup for easy deployment and execution.
- macOS:
brew install k6 - Windows:
choco install k6
- Ensure Docker is installed to run the test in a containerized environment.
|-- testWithAuthPrecondition.js # Main K6 script performing authentication and API tests
|-- payload.js # Contains authentication payload
|-- docker-compose.yml # Defines Docker setup for running the test
|-- README.md # Documentation file
- Update
payload.jswith the correct authentication credentials. - Run the test using:
k6 run testWithAuthPrecondition.js
- Build the Docker image:
docker-compose build
- Run the test in a container:
docker-compose up
The test is configured with the following options in testWithAuthPrecondition.js:
- Scenarios: Uses
constant-vusexecutor with 10 virtual users for 30 seconds. - Thresholds:
http_req_failed: Less than 2% failure rate.http_req_duration: 95% of requests should complete in under 300ms.
- Authentication:
- Authenticates with
identitySignInUrlusing credentials frompayload.js. - Extracts and stores the access token for subsequent API requests.
- Authenticates with
After execution, a summary report is generated as summary.html using k6-reporter.
- Authentication fails: Verify credentials in
payload.js. - K6 is not installed: Ensure it is installed correctly.
- Running in Docker issues: Ensure Docker is running and accessible.