Test Overview
This test simulates multiple users accessing a website at the same time to check if the website stays fast and stable. It verifies that the website responds within an acceptable time under load.
This test simulates multiple users accessing a website at the same time to check if the website stays fast and stable. It verifies that the website responds within an acceptable time under load.
import time from threading import Thread import requests responses = [] # Function to simulate a user sending a request def simulate_user(url): start = time.time() response = requests.get(url) end = time.time() responses.append((response.status_code, end - start)) # URL to test url = 'https://example.com' # Number of simulated users num_users = 5 threads = [] for _ in range(num_users): thread = Thread(target=simulate_user, args=(url,)) threads.append(thread) thread.start() for thread in threads: thread.join() # Check all responses for status, duration in responses: assert status == 200, f"Expected status 200 but got {status}" assert duration < 2, f"Response took too long: {duration} seconds"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test script is ready to run | - | PASS |
| 2 | Starts 5 threads to simulate 5 users sending requests to https://example.com | 5 threads running, each sending HTTP GET request | - | PASS |
| 3 | Each thread sends a GET request and records response status and time taken | Responses collected with status codes and durations | - | PASS |
| 4 | Main thread waits for all user threads to finish | All threads completed | - | PASS |
| 5 | Check each response status is 200 and response time is less than 2 seconds | All responses verified | Assert status == 200 and duration < 2 seconds for each response | PASS |
| 6 | Test ends with all assertions passed | Test completed successfully | - | PASS |