Debian Codegraph @

test/integration/targets/ansible-test-timeout/runme.sh

raw
1 #!/usr/bin/env bash
2 # Test ansible-test timeout functionality and the timeout callback.
3
4 source ../collection/setup.sh
5
6 set -eux -o pipefail
7
8 # Prime the venv so timeouts don't risk leaving a broken venv.
9 ansible-test integration noop --venv --color --truncate 0
10
11 echo "=== Test 1: ansible-test timeout already expired ==="
12 ansible-test env --timeout 0.0001 2>&1 | tee test1-env.txt
13
14 if ansible-test integration sleep --venv --color --truncate 0 2>&1 | tee test1.txt; then
15 echo "FAIL: expected ansible-test to fail due to expired timeout, but it passed."
16 exit 1
17 fi
18
19 grep -q "test timeout expired" test1.txt
20 grep -q "timeout may be too short" test1-env.txt
21
22 echo "=== Test 2: ansible-test timeout fires during a test ==="
23 # Use the sleep target (a shell script) so ansible-playbook doesn't run
24 # and the timeout callback doesn't intercept.
25 ansible-test env --timeout 0.1
26
27 if ansible-test integration sleep --venv --color --truncate 0 2>&1 | tee test2.txt; then
28 echo "FAIL: expected ansible-test to fail due to timeout, but it passed."
29 exit 1
30 fi
31
32 grep -q "time limit" test2.txt
33
34 echo "=== Test 3: timeout callback with deadline already passed ==="
35 # The timeout margin equals the timeout duration, so the callback
36 # deadline is guaranteed to be in the past by the time it loads.
37 # ansible-test's own timeout check passes since the deadline itself hasn't
38 # expired yet at startup.
39 ansible-test env --timeout 0.167 2>&1 | tee test3-env.txt
40
41 if ansible-test integration pause --venv --color --truncate 0 2>&1 | tee test3.txt; then
42 echo "FAIL: expected ansible-test to fail due to timeout traceback, but it passed."
43 exit 1
44 fi
45
46 grep -q "Tests aborted by the timeout callback" test3.txt
47 grep -q "deadline exceeded by" test3.txt
48 grep -q "timeout may be too short" test3-env.txt && exit 1
49
50 echo "=== Test 4: timeout callback fires while process is hung ==="
51 # Use a longer timeout so the callback deadline is in the future when it
52 # loads. The pause target keeps ansible-playbook alive long enough for the
53 # timeout callback to fire.
54 ansible-test env --timeout 0.25
55
56 if ansible-test integration pause --venv --color --truncate 0 2>&1 | tee test4.txt; then
57 echo "FAIL: expected ansible-test to fail due to timeout traceback, but it passed."
58 exit 1
59 fi
60
61 grep -q "Tests aborted by the timeout callback" test4.txt
62 grep -q "remaining" test4.txt
63
64 echo PASS