From f67f41af085fd5e6395f7f4e6de7ba49a1bbb232 Mon Sep 17 00:00:00 2001 From: a2nr Date: Fri, 2 Jan 2026 10:42:31 +0700 Subject: [PATCH] run test script inside podman --- test/Dockerfile | 25 ++++++++ test/LOAD_TESTING.md | 67 +++++++++++++++++++-- test/__pycache__/load_test.cpython-313.pyc | Bin 0 -> 5461 bytes test/podman-compose.yml | 33 ++++++++++ 4 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 test/Dockerfile create mode 100644 test/__pycache__/load_test.cpython-313.pyc create mode 100644 test/podman-compose.yml diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..0344adc --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.11-slim + +# Install necessary packages +RUN apt-get update && \ + apt-get install -y gcc build-essential && \ + rm -rf /var/lib/apt/lists/* + +# Set working directory +WORKDIR /app + +# Copy requirements and install Python dependencies +COPY test/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY . . + +# Expose port for Locust web interface +EXPOSE 8089 + +# Set the working directory to test +WORKDIR /app/test + +# Run Locust +CMD ["locust", "-f", "load_test.py", "--host=http://lms-c:5000"] \ No newline at end of file diff --git a/test/LOAD_TESTING.md b/test/LOAD_TESTING.md index fe23172..e986e75 100644 --- a/test/LOAD_TESTING.md +++ b/test/LOAD_TESTING.md @@ -4,13 +4,15 @@ This document describes how to perform load testing on the C Programming Learning Management System to ensure it can handle at least 50 concurrent students accessing the application. ## Requirements -- Python 3.7+ +- Python 3.7+ (for local testing) - Locust (installed via pip) +- Podman (for containerized testing) - The LMS application running on your local machine or a test server ## Setup -### 1. Install Locust +### Option 1: Local Installation +#### 1. Install Locust ```bash pip install locust ``` @@ -21,7 +23,7 @@ cd /path/to/lms-c/test pip install -r requirements.txt ``` -### 2. Ensure the LMS Application is Running +#### 2. Ensure the LMS Application is Running Start your LMS application: ```bash cd /path/to/lms-c @@ -34,9 +36,34 @@ python app.py By default, the application runs on `http://localhost:5000`. +### Option 2: Containerized Setup with Podman +The load testing can also be run in a containerized environment using Podman. This ensures consistency across different environments and simplifies setup. + +#### 1. Using the provided podman-compose file +A podman-compose file is provided in the test directory that sets up both the LMS application and the load testing service: + +```bash +cd /path/to/lms-c +podman-compose -f test/podman-compose.yml up --build +``` + +This will start both the LMS application and the Locust load testing service. The Locust web interface will be available at `http://localhost:8089`. + +#### 2. Running only the load test container against an existing LMS +If you already have the LMS running, you can run just the load test container: + +```bash +cd /path/to/lms-c +podman build -f test/Dockerfile -t lms-c-load-test . +podman run -p 8089:8089 --network=host lms-c-load-test +``` + +Note: Using `--network=host` allows the container to access the LMS running on localhost. + ## Running the Load Test -### Basic Load Test +### Local Load Test +#### Basic Load Test To run a load test simulating 50 users with a hatch rate of 2 users per second: ```bash cd /path/to/lms-c/test @@ -45,7 +72,7 @@ locust -f load_test.py --host=http://localhost:5000 Then open your browser and go to `http://localhost:8089` to configure the load test. -### Command Line Load Test +#### Command Line Load Test To run the load test directly from the command line without the web interface: ```bash locust -f load_test.py --host=http://localhost:5000 --users=50 --spawn-rate=2 --run-time=5m --headless @@ -57,6 +84,32 @@ This command will: - Run for 5 minutes (`--run-time=5m`) - Run in headless mode without the web interface (`--headless`) +### Containerized Load Test +#### Using Podman Compose +To run both the LMS and load testing services together: +```bash +cd /path/to/lms-c +podman-compose -f test/podman-compose.yml up --build +``` + +Then access the Locust web interface at `http://localhost:8089` to configure and start the load test. + +#### Running Load Test Only +To run just the load test against an existing LMS service: +```bash +cd /path/to/lms-c +podman build -f test/Dockerfile -t lms-c-load-test . +podman run -p 8089:8089 --network=host lms-c-load-test +``` + +#### Command Line Load Test in Container +To run the load test directly from the command line in headless mode: +```bash +cd /path/to/lms-c +podman build -f test/Dockerfile -t lms-c-load-test . +podman run --network=host lms-c-load-test locust -f /app/test/load_test.py --host=http://localhost:5000 --users=50 --spawn-rate=2 --run-time=5m --headless +``` + ## Test Scenarios The load test script simulates the following student behaviors: @@ -113,4 +166,6 @@ Consider monitoring system resources (CPU, memory, disk I/O) during the test usi ## Conclusion -This load testing setup allows you to verify that the C Programming Learning Management System can handle at least 50 concurrent students. Regular load testing should be performed, especially after major updates, to ensure the application continues to meet performance requirements. \ No newline at end of file +This load testing setup allows you to verify that the C Programming Learning Management System can handle at least 50 concurrent students. Regular load testing should be performed, especially after major updates, to ensure the application continues to meet performance requirements. + +Both local and containerized options are available to suit different deployment scenarios. The containerized approach using Podman ensures consistency across different environments and simplifies the setup process. \ No newline at end of file diff --git a/test/__pycache__/load_test.cpython-313.pyc b/test/__pycache__/load_test.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..494617da633cbb416dcb2d3107b3ca37c71efe9c GIT binary patch literal 5461 zcmc&&O>7&-6`tktXSMv1Vo8=PTk^_EEYY?^`bUi;%SjWR%Z)PhV7YTg#Uc9KcJx9pDFjN0R9VN@PwBoa4?0Xy7bQ z`LjV9JR71R3CsC&VH##>ghqPFJ|YMEh#Z>Z$9cCODzMTplt$(Pera2tPYRWf#q*|` zlWfhhbt5lXS*n+8X~Cq@Dd{b0=BZjNqTsxyQUjR_s-fn!qGs5Ve9f}8qBv`@3TC!! z*^+HamR>9uR9lnA(+8!jX=KZkVs*?$eb5M#g?(A1K_)Pn;LF+?WNl0)`m$()Ol*?H8f4KXS-e3O zlM^(aZ%=kO?Xs(|*R)0Tif+>ND9pE#7N@iY-Owb|-MlA~%mqoUD_AP~x;=kE7PH=p z*lyfIp)PrvPU8fdJ~>d=j={}x)3GKo zWMzKhT|!iFhZOA3+c+bCoIIE3lA+4v8-{M{YC*5K%PxauNEX_VX-K0|$+W?)Kwh{e zUDfSHNtLcZWw2`VGMI|PrPlue10}U=@7#)`R$P%zCB<6;YCBa0Tua&0Q5 z>NUnjOQvqv8fBTdWz%xjE>qS#8F4~v04L^IwqmG7%}IFnuD~dkX*dx#wVZIapu;>J zJ`d&`wQSWcTT0fSw6wy4BS6n3n1p7b-X+O7l3Fy2T1q`)(A1Q9)hK|kTB$bz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