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

Can't kill background process started in setup_file #912

Open
evadeflow opened this issue Apr 28, 2024 · 1 comment
Open

Can't kill background process started in setup_file #912

evadeflow opened this issue Apr 28, 2024 · 1 comment
Labels
Component: Bash Code Everything regarding the bash code Priority: High Broken behavior in specific environments like in parallel mode or only on some operating systems Size: Large Changes across several files Status: Unconfirmend No reproducer was provided or the reproducer did not work for maintainers. Type: Bug

Comments

@evadeflow
Copy link

evadeflow commented Apr 28, 2024

After reading through issue #205 and issue-205.bats, I'm able to start a nodeJS-based process in the background from setup_file() and it does not hang my tests. However, I can't figure out how to kill this process in teardown_file.

To Reproduce
Steps to reproduce the behavior:

It's probably easiest to see what I'm trying to do by applying this diff:

diff --git a/test/fixtures/bats/issue-205.bats b/test/fixtures/bats/issue-205.bats
index ddc826a..8382ad8 100644
--- a/test/fixtures/bats/issue-205.bats
+++ b/test/fixtures/bats/issue-205.bats
@@ -6,7 +6,7 @@ function bgfunc {
   close_non_std_fds
   get_open_fds
   echo "${FUNCNAME[1]} fds after: (${open_fds[*]})" >>"${LOG_FILE}"
-  sleep 10
+  sleep 2222
   echo "bgfunc done"
   return 0
 }
@@ -92,6 +92,11 @@ function otherfunc {

 setup_file() { # see issue #530
   bgfunc &
+  SFPID=$!
+}
+
+teardown_file() {
+  kill ${SFPID}
 }

 @test "min bg" {

and then running ./bin/bats test/bats.bats. When the test suite completes, run ps -ef | grep "sleep 2222" | grep -v grep.

Expected behavior
I expected to see at most one instance of sleep 2222 running, but there are two:

$ ps -ef | grep "sleep 2222" | grep -v grep
bosch     5883    31  0 15:04 pts/3    00:00:00 sleep 2222
bosch     5887  5872  0 15:04 pts/3    00:00:00 sleep 2222

Environment (please complete the following information):

  • Bats version 1.11.0 (master@a751f3d)
  • operating system: WSL2 Linux, Ubuntu 20.04)
  • bash --version: [e.g. 5.1]: GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
  • Install method: git submodule

Additional context
I'm pretty unfamiliar with BATS, so I may be doing something stupid/silly. Attempting to store the PID in setup_file and then killing it in teardown_file seemed reasonable, but it doesn't work, so... how does one start a service in background and then kill it once all the tests have completed? I just want to spin up my app, send it some requests using curl, and verify that the responses are what's expected.

@evadeflow evadeflow added Priority: NeedsTriage Issue has not been vetted yet Type: Bug labels Apr 28, 2024
@martin-schulze-vireso martin-schulze-vireso added Priority: High Broken behavior in specific environments like in parallel mode or only on some operating systems Status: Unconfirmend No reproducer was provided or the reproducer did not work for maintainers. Component: Bash Code Everything regarding the bash code Size: Large Changes across several files and removed Priority: NeedsTriage Issue has not been vetted yet labels May 4, 2024
@martin-schulze-vireso
Copy link
Member

Probably FD3 staying open again. Maybe the same issue as in #530

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Bash Code Everything regarding the bash code Priority: High Broken behavior in specific environments like in parallel mode or only on some operating systems Size: Large Changes across several files Status: Unconfirmend No reproducer was provided or the reproducer did not work for maintainers. Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants