How shukla-shreyansh/loadtest-locust-python works
Main Components
• Locust Engine: Represented by locustfile.py, which is the entry point for running the tests.
• Tasks Module: Contains base_task.py and api_tasks.py in the tasks directory. These files define the load test tasks and API calls.
• Configuration Module: In the config directory (settings.py, loader.py, and __init__.py) managing project settings and configurations.
• Utilities Module: Located in the utils directory (auth.py and reporting.py) for support functions like authentication and custom reporting (e.g., for generating the P99 response time graph).
• External Files: apis.json and payloads.json, which contain API endpoints and payload data. Also, token.json (although mentioned in README as token.txt) relates to token-based authentication.
• Deployment & Orchestration: Dockerfile and docker-compose.yml define containerization and distributed testing setup.
• Environment Files: Additional items like requirements.txt and locustfile.py illustrate dependency management and test initiation.
Relationships and Interactions
• The locustfile.py serves as the orchestrator for Locust which uses the task definitions from the tasks module.
• Tasks call utility functions (like authentication in utils/auth.py) to perform API endpoint testing, with configuration values handed out from the config module.
• The shared configuration (config/settings.py) influences how tasks are executed (e.g., number of users, spawn rate) and sets up global parameters.
• The Docker and Docker Compose setup indicate that the application can run in both a local development mode and in a scaled, distributed environment, with worker nodes initiated via docker-compose.
Architectural Patterns and Design Principles
• Modularity: Each functional area (configuration, tasks, utilities) is separated into its own directory for easy extension.
• Extensibility: Clear points for customization (e.g., adding new API tasks, modifying authentication handler, extending reporting in utils/reporting.py).
• Separation of Concerns: Different aspects of the load testing system (configuration, task definitions, and supporting utilities) are cleanly separated, improving maintainability.
• Containerization and Scaling: Docker and Docker Compose files allow the testing framework to run locally or in a distributed system.
Key Technologies and Tools
• Locust: For executing the load tests.
• Docker & Docker Compose: For containerization and orchestration in distributed test runs.
• Python Environment Management: Virtual environments and requirements.txt for dependency management.
• Reporting Tools: Custom reporting within utils/reporting.py, which generates output graphs like the P99 response time graph.
Recommendations
• Locust Entry Point (locustfile.py)
• Tasks Module (tasks/base_task.py and tasks/api_tasks.py)
• Configuration (config/settings.py, config/loader.py)
• Utilities (utils/auth.py, utils/reporting.py)
• Data Files (apis.json, payloads.json, token.json)
• Deployment Infrastructure (Dockerfile and docker-compose.yml)
• Use clear labels for each block/component.
• From configuration to tasks (illustrate that tasks fetch settings).
• From tasks to utilities (tasks call auth functions or reporting functions).
• Data flow from external JSON data into the tasks.
• External integrations like Docker Compose (showing how scaling happens) and the dependency on configuration files.
• To include annotations that highlight customization points (like where to add new API tasks or modify authentication).