Skip to content

Commit

Permalink
Merge pull request #657 from marc-hb/fix-infinite-j
Browse files Browse the repository at this point in the history
Fix infinite wait when invoking "bats -j5" instead of "bats -j 5"
  • Loading branch information
martin-schulze-vireso committed Oct 5, 2022
2 parents c0d2ca1 + 58fa597 commit e3bd116
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to

* `shfmt` all files and enforce via CI (#651)
* avoid kernel warning flood/hang with CTRL+C on Bash 5.2 RC (#656)
* Fix infinite wait with (invalid) `-j<n>` (without space) (#657)

## [1.8.0] - 2022-09-15

Expand Down
5 changes: 5 additions & 0 deletions libexec/bats-core/bats-exec-file
Expand Up @@ -285,6 +285,11 @@ bats_read_tests_list_file() {
bats_run_tests() {
bats_exec_file_status=0

if [[ "$num_jobs" -lt 1 ]]; then
printf 'Invalid number of jobs: %s\n' "$num_jobs" >&2
exit 1
fi

if [[ "$num_jobs" != 1 && "${BATS_NO_PARALLELIZE_WITHIN_FILE-False}" == False ]]; then
export BATS_SEMAPHORE_NUMBER_OF_SLOTS="$num_jobs"
bats_run_tests_in_parallel "$BATS_RUN_TMPDIR/parallel_output" || bats_exec_file_status=1
Expand Down
10 changes: 10 additions & 0 deletions test/parallel.bats
Expand Up @@ -5,6 +5,9 @@ bats_require_minimum_version 1.5.0
load test_helper
fixtures parallel

# shellcheck disable=SC2034
BATS_TEST_TIMEOUT=10 # only intended for the "short form ..."" test

setup() {
type -p parallel &>/dev/null || skip "--jobs requires GNU parallel"
(type -p flock &>/dev/null || type -p shlock &>/dev/null) || skip "--jobs requires flock/shlock"
Expand Down Expand Up @@ -208,3 +211,10 @@ check_parallel_tests() { # <expected maximum parallelity>
@test "BATS_NO_PARALLELIZE_WITHIN_FILE does not work from inside test function" {
DISABLE_IN_TEST_FUNCTION=1 reentrant_run ! bats --jobs 2 "$FIXTURE_ROOT/must_not_parallelize_within_file.bats"
}

@test "Short form typo does not run endlessly" {
unset BATS_NO_PARALLELIZE_ACROSS_FILES
run bats -j2 "$FIXTURE_ROOT/../bats/passing.bats"
(( SECONDS < 5 ))
[ "${lines[1]}" = 'Invalid number of jobs: -2' ]
}
4 changes: 4 additions & 0 deletions test/timeout.bats
Expand Up @@ -23,3 +23,7 @@ bats_require_minimum_version 1.5.0
[ "${lines[3]}" == "# \`sleep \"\${SLEEP?}\"' failed due to timeout" ]
((SECONDS < 10)) || false
}

@test "sleep in run" {
run sleep 10
}

0 comments on commit e3bd116

Please sign in to comment.