|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -set -e # Exit immediately if a command fails |
| 3 | +set -e |
4 | 4 |
|
5 | | -# CI fast-fail defaults (override via env) |
6 | | -: "${SHINY_TEST_TIMEOUT_SECS:=10}" # App startup fast-fail (seconds) |
7 | | -: "${PYTEST_PER_TEST_TIMEOUT:=60}" # Per-test timeout (seconds) |
8 | | -: "${PYTEST_SUITE_TIMEOUT:=6m}" # Whole pytest run timeout |
9 | | -: "${PYTEST_MAXFAIL:=1}" # Fail fast on first failure |
10 | | -: "${PYTEST_XDIST_WORKERS:=auto}" # Parallel workers for pytest-xdist |
| 5 | +# Defaults (override via env) |
| 6 | +: "${SHINY_TEST_TIMEOUT_SECS:=10}" |
| 7 | +: "${PYTEST_PER_TEST_TIMEOUT:=60}" |
| 8 | +: "${PYTEST_SUITE_TIMEOUT:=6m}" |
| 9 | +: "${PYTEST_MAXFAIL:=1}" |
| 10 | +: "${PYTEST_XDIST_WORKERS:=auto}" |
| 11 | +: "${ATTEMPTS:=3}" |
11 | 12 | export SHINY_TEST_TIMEOUT_SECS |
12 | 13 |
|
13 | | -# Function to log with timestamp |
14 | 14 | log_with_timestamp() { |
15 | 15 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" |
16 | 16 | } |
17 | 17 |
|
18 | | -# Function to cleanup hanging processes |
19 | 18 | cleanup_processes() { |
20 | 19 | log_with_timestamp "Cleaning up any hanging processes..." |
21 | 20 | pkill -f "playwright" || true |
22 | 21 | pkill -f "chromium" || true |
23 | 22 | pkill -f "pytest" || true |
24 | 23 | } |
25 | 24 |
|
26 | | -# Set up trap to cleanup on exit |
27 | 25 | trap cleanup_processes EXIT |
28 | 26 |
|
29 | | -for i in {1..3} |
30 | | -do |
31 | | - log_with_timestamp "Starting Attempt $i of 3" |
| 27 | +for i in $(seq 1 "$ATTEMPTS"); do |
| 28 | + log_with_timestamp "Starting attempt $i of $ATTEMPTS" |
32 | 29 |
|
33 | | - # Clean up results from previous attempt to ensure a clean slate |
34 | 30 | rm -rf results/ |
35 | 31 | mkdir -p results/ |
36 | 32 | rm -f test-results.xml |
|
43 | 39 | --log-dir results/ \ |
44 | 40 | --log-format json |
45 | 41 |
|
46 | | - log_with_timestamp "[Attempt $i] Running Tests..." |
| 42 | + log_with_timestamp "[Attempt $i] Running tests..." |
47 | 43 | test_exit_code=0 |
48 | | - # Disable exit on error just for the pytest command to check the exit code |
49 | 44 | set +e |
50 | 45 | timeout "$PYTEST_SUITE_TIMEOUT" pytest tests/inspect-ai/apps \ |
51 | 46 | -n "$PYTEST_XDIST_WORKERS" --dist loadfile \ |
|
57 | 52 | --timeout="$PYTEST_PER_TEST_TIMEOUT" \ |
58 | 53 | --timeout-method=signal \ |
59 | 54 | -v || test_exit_code=$? |
60 | | - # Re-enable exit on error immediately |
61 | 55 | set -e |
62 | 56 |
|
63 | | - # Check if timeout occurred |
64 | 57 | if [ "${test_exit_code:-0}" -eq 124 ]; then |
65 | | - log_with_timestamp "Tests timed out on attempt $i - this may indicate hanging tests" |
| 58 | + log_with_timestamp "Tests timed out on attempt $i (possible hang)" |
66 | 59 | cleanup_processes |
67 | 60 | exit 1 |
68 | 61 | fi |
69 | 62 |
|
70 | | - # Check if tests failed and how many failures occurred |
71 | 63 | if [ "${test_exit_code:-0}" -ne 0 ]; then |
72 | | - failure_count=$(grep -o 'failures="[0-9]*"' test-results.xml | grep -o '[0-9]*' || echo "0") |
| 64 | + if [ -f test-results.xml ]; then |
| 65 | + failure_count=$(grep -o 'failures="[0-9]*"' test-results.xml | grep -o '[0-9]*' || echo "0") |
| 66 | + else |
| 67 | + failure_count=0 |
| 68 | + fi |
73 | 69 | log_with_timestamp "Found $failure_count test failures on attempt $i" |
74 | 70 |
|
75 | | - # Fail the workflow if more than 1 test failed |
76 | 71 | if [ "$failure_count" -gt 1 ]; then |
77 | 72 | log_with_timestamp "More than 1 test failed on attempt $i - failing CI" |
78 | 73 | exit 1 |
79 | 74 | fi |
80 | 75 | fi |
81 | | - log_with_timestamp "Attempt $i of 3 Succeeded" |
| 76 | + |
| 77 | + log_with_timestamp "Attempt $i of $ATTEMPTS succeeded" |
82 | 78 | done |
83 | 79 |
|
84 | | -log_with_timestamp "All 3 evaluation and test runs passed successfully." |
| 80 | +log_with_timestamp "All $ATTEMPTS evaluation and test runs passed successfully." |
0 commit comments