Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite wait when invoking "bats -j5" instead of "bats -j 5" #657

Merged
merged 3 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want to test the check that was added in this PR then I think it should be:

Suggested change
run bats -j2 "$FIXTURE_ROOT/../bats/passing.bats"
run bats -j -2 "$FIXTURE_ROOT/../bats/passing.bats"

Otherwise this test will switch to covering a completely different part of the code the moment you refactor the options parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional test submitted in #693

(( SECONDS < 5 ))
[ "${lines[1]}" = 'Invalid number of jobs: -2' ]
}
4 changes: 4 additions & 0 deletions test/timeout.bats
Original file line number Diff line number Diff line change
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
}