@@ -34,6 +34,8 @@ E2E_TEST_DIR="$(dirname "$(realpath "$0")")/.."
3434export LOCAL_CONFIG_DIR=" $E2E_TEST_DIR /config"
3535export LOCAL_RESULTS_DIR=" $E2E_TEST_DIR /results"
3636export LOADTEST_CONFIG=" /config/smoke-test-config.yaml"
37+ # Clean previous results to avoid false positives
38+ rm -f " $LOCAL_RESULTS_DIR /results.txt" " $LOCAL_RESULTS_DIR /report.html" " $LOCAL_RESULTS_DIR /docker-compose.log"
3739# Start services
3840echo " Starting services with docker compose..."
3941docker compose up --build -d
@@ -66,10 +68,58 @@ if [ $ELAPSED -ge $MAX_WAIT ]; then
6668 docker compose logs
6769fi
6870
71+ # If results exist, wait for both containers to stop (max 30 seconds)
72+ if [ -f " $LOCAL_RESULTS_DIR /results.txt" ]; then
73+ echo " Waiting for containers to stop..."
74+ TIMEOUT=30
75+ ELAPSED=0
76+ while [ $ELAPSED -lt $TIMEOUT ]; do
77+ RUNNING_CONTAINERS=$( docker compose ps --status running -q 2> /dev/null || true)
78+ if [ -z " $RUNNING_CONTAINERS " ]; then
79+ echo " All containers stopped."
80+ break
81+ fi
82+ sleep 2
83+ ELAPSED=$(( ELAPSED + 2 ))
84+ echo " Waiting for containers to stop... ($ELAPSED /$TIMEOUT seconds)"
85+ done
86+ if [ $ELAPSED -ge $TIMEOUT ]; then
87+ echo " WARNING: Some containers did not stop within $TIMEOUT seconds."
88+ fi
89+ fi
90+
91+ # Check if any containers are still running after shutdown
92+ echo " Checking for leftover containers..."
93+ REMAINING_CONTAINERS=$( docker compose ps --status running -q 2> /dev/null || true)
94+ if [ -n " $REMAINING_CONTAINERS " ]; then
95+ echo " ERROR: Containers still running after shutdown:"
96+ docker compose ps
97+ EXIT_CODE=1
98+ fi
99+
100+ # Check for any Selenium browser containers that might have been left running
101+ echo " Checking for leftover Selenium containers..."
102+ SELENIUM_CONTAINERS=$( docker ps -q --filter " name=selenium" 2> /dev/null || true)
103+ if [ -n " $SELENIUM_CONTAINERS " ]; then
104+ echo " ERROR: Selenium containers still running:"
105+ docker ps --filter " name=selenium"
106+ EXIT_CODE=1
107+ fi
108+
69109# Stop services
70110docker compose logs > $LOCAL_RESULTS_DIR /docker-compose.log 2>&1
71111echo " Stopping services..."
72112docker compose down
113+ # Stop and remove any remaining selenium containers
114+ SELENIUM_CONTAINERS=$( docker ps -aq --filter " name=selenium" 2> /dev/null || true)
115+ if [ -n " $SELENIUM_CONTAINERS " ]; then
116+ echo " Removing remaining Selenium containers..."
117+ docker rm -f $SELENIUM_CONTAINERS > /dev/null 2>&1 || true
118+ fi
119+
120+ if [ $EXIT_CODE -eq 0 ]; then
121+ echo " ✓ All containers stopped successfully"
122+ fi
73123
74124 # Check results
75125 echo " Checking test results..."
@@ -203,7 +253,7 @@ docker compose down
203253 rm -f " $HTML_FILE "
204254 rm -f " $LOCAL_RESULTS_DIR /docker-compose.log"
205255 else
206- echo " Keeping result files for debugging. Remember to remove them manually before re-running the test. "
256+ echo " Keeping result files for debugging."
207257 fi
208258else
209259 echo " ERROR: Results file or HTML report not found at $LOCAL_RESULTS_DIR /results.txt or report.html"
0 commit comments