Skip to content

Commit

Permalink
Make timing more robust against slow CI runners
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schulze-vireso committed Jul 25, 2022
1 parent 0eee5b4 commit ef7c281
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libexec/bats-core/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ bats_timout() {
bats_strike_back() {
# This will kill the killers in the case he is sleeping,
local killer_pid=$1
if kill -0 "$killer_pid" > /dev/null; then
if kill -0 "$killer_pid" &> /dev/null; then
pkill -PIPE -P "$killer_pid" &> /dev/null
wait "$killer_pid" &> /dev/null
fi
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/timeout/sleep2.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

@test "my sleep 2" {
sleep 2
@test "my sleep ${SLEEP:-2}" {
sleep ${SLEEP:-2}
}

8 changes: 4 additions & 4 deletions test/timeout.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ fixtures timeout
bats_require_minimum_version 1.5.0

@test "test faster than timeout" {
run -0 env BATS_TIMEOUT=3 bats "$FIXTURE_ROOT"
run -0 env BATS_TIMEOUT=3 SLEEP=2 bats "$FIXTURE_ROOT"
[ "${lines[0]}" == '1..1' ]
[ "${lines[1]}" == 'ok 1 my sleep 2' ]
[ "${#lines[@]}" -eq 2 ]
}

@test "test longer than timeout" {
run ! env BATS_TIMEOUT=1 bats "$FIXTURE_ROOT"
run ! env BATS_TIMEOUT=1 SLEEP=10 bats "$FIXTURE_ROOT"
[ "${lines[0]}" == '1..1' ]
[ "${lines[1]}" == 'not ok 1 my sleep 2 # timeout after 1s' ]
[ "${lines[1]}" == 'not ok 1 my sleep 10 # timeout after 1s' ]
[ "${lines[2]}" == '# (in test file test/fixtures/timeout/sleep2.bats, line 3)' ]
[ "${lines[3]}" == "# \`sleep 2' failed with status 141" ]
[ "${lines[3]}" == "# \`sleep \${SLEEP:-2}' failed with status 141" ]
[ "${#lines[@]}" -eq 4 ]
}

0 comments on commit ef7c281

Please sign in to comment.