-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Framework, Bash, and operating system version information
_GO_CORE_VERSION: v1.7.0
BASH_VERSION: 3.2.57(1)-release
OSTYPE: darwin16
_GO_PLATFORM_ID: macos
_GO_PLATFORM_VERSION_ID: 10.12.6
Description
When trying to use background-process
based on the basic usage documentation at the top of a file, a simple test case hangs indefinitely if there is no match in the output.
Consider the following, where support/testfx
also sources background-process
and helpers
.
#!/usr/bin/env bats
load support/testfx
setup() {
mkdir "$BATS_TEST_ROOTDIR"
}
teardown() {
remove_bats_test_dirs
}
@test "works" {
skip_if_missing_background_utilities
run_in_background bash -c 'echo hi; sleep 60'
wait_for_background_output 'hi' '1'
stop_background_run
}
@test "fails" {
skip_if_missing_background_utilities
run_in_background bash -c 'echo hi; sleep 60'
wait_for_background_output 'fail' '1'
stop_background_run
}
The output of the test is then:
✓ works
✗ fails
(in test file /sanitized/test.bats, line 23)
`wait_for_background_output 'fail'' failed
/sanitized/go-script-bash-dl/lib/bats/background-process: line 101: 82517 Terminated: 15 "${input_cmd[@]}"
Output did not match regular expression:
'fail'
OUTPUT:
------
hi
2 tests, 1 failure
real 1m0.206s
user 0m0.158s
sys 0m0.073s
The only reason the fails
test exits is because the sleep 60
finally completes. In reality, it should be terminated much sooner after wait_for_background_output
times out after 1 second. Leaving off the manual timeout and using the default timeout for wait_for_background_output
provides the same result.
Looking through the bats-background-process
test cases I don't see any that use the recommended usage pattern. They all seem to use a different pattern and even invoke wait_for_background_output
using the bats
run
function.
Are the docs out of date? Is this a bug? It sure seems like a bug since testing a background process implies the process should not have to exit for the test to work.