Test Overview
This test simulates multiple users accessing a web application simultaneously to verify if the system can handle the expected load without performance degradation or failure.
This test simulates multiple users accessing a web application simultaneously to verify if the system can handle the expected load without performance degradation or failure.
from locust import HttpUser, task, between class WebsiteUser(HttpUser): wait_time = between(1, 3) @task def load_homepage(self): response = self.client.get("/") assert response.status_code == 200 @task(3) def load_about_page(self): response = self.client.get("/about") assert response.status_code == 200 # To run this test, use the command: locust -f this_script.py --headless -u 10 -r 2 -t 30s # This runs 10 users, spawning 2 users per second, for 30 seconds.
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts by launching Locust with 10 users and spawn rate of 2 users per second. | Locust initializes and prepares to simulate users. | - | PASS |
| 2 | First simulated user opens the homepage by sending GET request to '/' endpoint. | Web server receives request and processes it. | Check that response status code is 200 (OK). | PASS |
| 3 | User waits between 1 to 3 seconds before next action. | User is idle for a short random time. | - | PASS |
| 4 | User sends GET request to '/about' page three times more frequently than homepage. | Server processes multiple requests to '/about' endpoint. | Each response status code must be 200. | PASS |
| 5 | More users spawn gradually until total 10 users are active, repeating the tasks. | Server handles increasing load of simultaneous requests. | All responses return status code 200 without errors. | PASS |
| 6 | Test runs for 30 seconds, monitoring server response times and error rates. | Server performance metrics are collected. | No server errors or timeouts occur during test duration. | PASS |
| 7 | Test ends and Locust generates a report summarizing requests, failures, and response times. | Test report is available for analysis. | Verify that failure count is zero and average response time is acceptable. | PASS |