@@ -142,7 +142,75 @@ jobs:
142142 cd backend
143143 # Exclude rate_limit tests from CI/CD - they consume quota and should run separately
144144 # To run rate limit tests locally: pytest tests/e2e/smoke -m rate_limit
145- pytest tests/e2e/smoke -m "not rate_limit" -n 3 -v --tb=short
145+
146+ MAX_RETRIES=2
147+
148+ # Run all tests first
149+ set +e
150+ pytest tests/e2e/smoke -m "not rate_limit" -n 3 -v --tb=short 2>&1 | tee pytest_output.txt
151+ EXIT_CODE=${PIPESTATUS[0]}
152+ set -e
153+
154+ if [ $EXIT_CODE -eq 0 ]; then
155+ echo "All tests passed!"
156+ exit 0
157+ fi
158+
159+ # Count failures from pytest output
160+ FAILURES=$(grep -oP '\d+(?= failed)' pytest_output.txt | head -1 || echo "0")
161+ echo "Detected $FAILURES test failure(s)"
162+
163+ # If 3 or more failures, don't retry
164+ if [ "$FAILURES" -ge 3 ]; then
165+ echo "3 or more tests failed. Not retrying."
166+ exit 1
167+ fi
168+
169+ # Retry only the failed tests
170+ ATTEMPT=1
171+ while [ $ATTEMPT -le $MAX_RETRIES ]; do
172+ echo ""
173+ echo "=========================================="
174+ echo "Retry attempt $ATTEMPT of $MAX_RETRIES (running ONLY failed tests)"
175+ echo "=========================================="
176+ sleep 5
177+
178+ set +e
179+ pytest tests/e2e/smoke -m "not rate_limit" --lf -n 3 -v --tb=short 2>&1 | tee pytest_retry_output.txt
180+ EXIT_CODE=${PIPESTATUS[0]}
181+ set -e
182+
183+ if [ $EXIT_CODE -eq 0 ]; then
184+ echo "Failed tests passed on retry!"
185+ exit 0
186+ fi
187+
188+ ATTEMPT=$((ATTEMPT + 1))
189+ done
190+
191+ # If we get here, tests failed after retries
192+ echo "Tests failed after $MAX_RETRIES retry attempts"
193+ exit 1
194+
195+ - name : Print service logs on failure
196+ if : failure()
197+ run : |
198+ echo "=========================================="
199+ echo "FASTAPI SERVER LOGS (last 200 lines)"
200+ echo "=========================================="
201+ docker logs airweave-backend --tail 200 2>&1 || echo "Could not fetch backend logs"
202+
203+ echo ""
204+ echo "=========================================="
205+ echo "TEMPORAL WORKER LOGS (last 800 lines)"
206+ echo "=========================================="
207+ docker logs airweave-temporal-worker --tail 800 2>&1 || echo "Could not fetch worker logs"
208+
209+ echo ""
210+ echo "=========================================="
211+ echo "All running containers:"
212+ echo "=========================================="
213+ docker ps
146214
147215 - name : Cleanup Docker containers
148216 if : always()
0 commit comments