bats
bats copied to clipboard
nohup command causes bats-format-tap-stream hang
Hi, I was stuck in this issue few days. Seems nohup command in following test code would cause bats-format-tap-stream hang and never exit except Ctrl+C to interrupt. Anyone know how to fix it?
#!/usr/bin/env bats
load test_helper
fixtures bats
@test "a passing test" {
nohup /bin/sleep 30000000 &
echo 'hello'
}
$ bin/bats -t test/case.bats
1..1
ok 1 a passing test
<<<==== hang here
I suffered the same problem. In general when a daemon is running in background and test fails, then it's not recognized until CTRL-C.
I will explain you a workaroung (with sideeffects):
Substitute last line of libexec/bats file:
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
with
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}"
then you lost "pretty" formatter but your problem is solved.
@ricardo-perezb thx your workaround. I'm having another solution that let $formatter read input from file, not pipeline. Bcoz I have other code to analyze the test result with pretty format. Anyway, hope bats can consider how to handle this scenario. In mostly test case, using nohup to start/stop daemon is often case.
This is the same issue as https://github.com/sstephenson/bats/issues/80 and https://github.com/sstephenson/bats/issues/46. The comment: https://github.com/sstephenson/bats/issues/80#issuecomment-174101686 provides a good workaround.