bats icon indicating copy to clipboard operation
bats copied to clipboard

nohup command causes bats-format-tap-stream hang

Open pxy0592 opened this issue 8 years ago • 3 comments

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

pxy0592 avatar Jan 12 '16 03:01 pxy0592

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 avatar Jan 13 '16 20:01 ricardo-perezb

@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.

pxy0592 avatar Jan 14 '16 02:01 pxy0592

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.

xmik avatar Feb 28 '17 12:02 xmik