Skip to content

Print the current command when aborting a test via CTRL-C #368

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

Conversation

martin-schulze-vireso
Copy link
Member

@martin-schulze-vireso martin-schulze-vireso commented Oct 16, 2020

Motivation: I was working on a hanging test so I wondered how I could see where it hangs. Since I would CTRL-C the test anyways, I thought it would be nice to have a printout of the current command when I abort.

This may serve as a template for future test timeout handling, which should offer similar functionality for CI builds.

TODOs:

@martin-schulze-vireso martin-schulze-vireso requested a review from a team as a code owner October 16, 2020 19:39
@martin-schulze-vireso martin-schulze-vireso changed the title More information about the currently running command when aborting a test via CTRL-C Print the current command when aborting a test via CTRL-C Nov 6, 2020
@sublimino
Copy link
Member

This looks to be really useful. I merged master, which gives a few test failures, could you rebase or merge in master so I can test again @martin-schulze-vireso?

There appears to be a race condition (?) running the tests in parallel (the below error text), which is fixed by turning test_helper::cleanup_tmpdir into a no-op (this is still cleaned unless bats uses --no-tempdir-cleanup). Then all the tests pass.

 ✓ Test nounset does not trip up bats' internals (see #385)                                                                                                    ✗ CTRL-C aborts and fails the current test                                                                                                                     (in test file test/bats.bats, line 747)                                                                                                                         `[[ "${lines[1]}" == "not ok 1 test" ]]' failed                                                                                                          
   cat: /tmp/bats-run-3553851/bats-test-tmp//test_CTRL-2dC_aborts_and_fails_the_current_test.log: No such file or directory                                    ✗ CTRL-C aborts and fails the current run                                                                                                                   
   (in test file test/bats.bats, line 780)
     `[[ "${lines[1]}" == "not ok 1 test" ]]' failed
   cat: /tmp/bats-run-3553851/bats-test-tmp//test_CTRL-2dC_aborts_and_fails_the_current_run.log: No such file or directory
 ✗ CTRL-C aborts and fails the current teardown                                                                                                              
   (in test file test/bats.bats, line 813)
     `[[ "${lines[1]}" == "not ok 1 empty" ]]' failed
   cat: /tmp/bats-run-3553851/bats-test-tmp//test_CTRL-2dC_aborts_and_fails_the_current_teardown.log: No such file or directory
 ✓ CTRL-C aborts and fails the current setup_file                                                                                                            
 ✗ CTRL-C aborts and fails the current teardown_file                                                                                                         
   (in test file test/bats.bats, line 878)
     `[[ "${lines[0]}" == "1..1" ]]' failed
   cat: /tmp/bats-run-3553851/bats-test-tmp//test_CTRL-2dC_aborts_and_fails_the_current_teardown-2d5ffile.log: No such file or directory
 ✓ setup_file is run once per file

Randomly hammering ctrl-c during bats own execution occasionally (1 in 100?!) misses, perhaps that could say "not in function" or whatever the equivalent may be?

 ✓ tap passing and skipping tests
 ✗ tap passing and skipping tests
   Interrupted (SIGINT/CTRL-C) at:
   bats warning: Executed 11 instead of expected 147 tests

147 tests, 1 failure, 136 not run

I managed to break it with a typo that broke a regex.

In the event that an error occurs internal to bats, the exit code handler hangs:

$ bin/bats --formatter tap test/ --jobs 10--no-tempdir-cleanup       
 1..149                                                                                                                                                                                             
/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/libexec/bats-core/bats-exec-suite: line 130: [[: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")         
/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/lib/bats-core/semaphore.bash: line 98: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")                   
^C/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/lib/bats-core/semaphore.bash: line 98: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")                 
rm: cannot remove '/tmp/bats-run-3371479/semaphores/slot-': No such file or directory                                                                                                               
^Cok 1 no arguments prints message and usage instructions                                                                         

Notably this doesn't work in Docker right now as there is no exit code handler, we just get

ok 28 load sources relative scripts with filename extension
^Cwrite /dev/stdout: broken pipe

Overall looks great!

@martin-schulze-vireso martin-schulze-vireso force-pushed the feature/abort_finishes_tests branch from fc2fc6a to 53ba644 Compare April 18, 2021 07:42
@martin-schulze-vireso
Copy link
Member Author

Thanks for the review @sublimino.

This looks to be really useful. I merged master, which gives a few test failures, could you rebase or merge in master so I can test again @martin-schulze-vireso?

I rebased onto current master.

There appears to be a race condition (?) running the tests in parallel (the below error text), which is fixed by turning test_helper::cleanup_tmpdir into a no-op (this is still cleaned unless bats uses --no-tempdir-cleanup). Then all the tests pass.

That should not be part of this PR. I think #413 already has a fix for that.

Randomly hammering ctrl-c during bats own execution occasionally (1 in 100?!) misses, perhaps that could say "not in function" or whatever the equivalent may be?

 ✓ tap passing and skipping tests
 ✗ tap passing and skipping tests
   Interrupted (SIGINT/CTRL-C) at:
   bats warning: Executed 11 instead of expected 147 tests

147 tests, 1 failure, 136 not run

I reworked the message to this format which is more agnostic to the current execution progress:

....
✗ summary passing tests

   (in test file test/bats.bats, line 57)
     `run filter_control_sequences bats -p "$FIXTURE_ROOT/passing.bats"' failed with status 130

   Received SIGINT, aborting ... 

   bats warning: Executed 8 instead of expected 154 tests

154 tests, 1 failure, 146 not run

So the Received SIGINT, aborting ... part will always come after the test output. If there is none, it looks like:

...
 ✓ summary passing tests

   Received SIGINT, aborting ... 

   bats warning: Executed 8 instead of expected 154 tests

154 tests, 0 failures, 146 not run

bats still exits non null in this case!

I managed to break it with a typo that broke a regex.

In the event that an error occurs internal to bats, the exit code handler hangs:

$ bin/bats --formatter tap test/ --jobs 10--no-tempdir-cleanup       
 1..149                                                                                                                                                                                             
/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/libexec/bats-core/bats-exec-suite: line 130: [[: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")         
/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/lib/bats-core/semaphore.bash: line 98: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")                   
^C/usr/local/src/tmp/1611504215-bats-core.5JONGJ2/lib/bats-core/semaphore.bash: line 98: 10--no-tempdir-cleanup: syntax error in expression (error token is "--no-tempdir-cleanup")                 
rm: cannot remove '/tmp/bats-run-3371479/semaphores/slot-': No such file or directory                                                                                                               
^Cok 1 no arguments prints message and usage instructions                                                                         

I could not reproduce that with the current code. Could you give more details?

Notably this doesn't work in Docker right now as there is no exit code handler, we just get

ok 28 load sources relative scripts with filename extension
^Cwrite /dev/stdout: broken pipe

I am not sure what you mean by exit code handler. Could you give more detail on how you started the container and how you sent the INT signal?

@martin-schulze-vireso martin-schulze-vireso force-pushed the feature/abort_finishes_tests branch from 485cfbb to bf39c31 Compare April 18, 2021 15:39
@martin-schulze-vireso martin-schulze-vireso added this to the 1.4.0 Release milestone Apr 25, 2021
@rockandska
Copy link
Contributor

I am not sure what you mean by exit code handler. Could you give more detail on how you started the container and how you sent the INT signal?

Since @sublimino tried this feature before #407 , he hit the issue solved by this PR.
Should not hit this issue anymore now.

martin-schulze-vireso added a commit to martin-schulze-vireso/bats-core that referenced this pull request Jun 19, 2021
@martin-schulze-vireso martin-schulze-vireso force-pushed the feature/abort_finishes_tests branch from 6b7a090 to 5a32e48 Compare June 19, 2021 21:40
@martin-schulze-vireso martin-schulze-vireso merged commit eac1e9d into bats-core:master Jun 19, 2021
@martin-schulze-vireso martin-schulze-vireso deleted the feature/abort_finishes_tests branch May 23, 2022 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants