grosser / parallel_tests

Ruby: 2 CPUs = 2x Testing Speed for RSpec, Test::Unit and Cucumber
3.39k stars 495 forks source link

Check for tty with tty? instead of comparing pgid #971

Closed timreinke closed 2 months ago

timreinke commented 2 months ago

Hi,

I think there's a problem with how the SIGINT forwarding works. Checking Process.getpgid(child_pid) != Process.pid can be wrong in both directions:

In my case, I want to perform cleanup (release selenium grid handles) when a github workflow is cancelled. If I define my step as:

# use exec so signals are forwarded
run: exec bundle exec parallel_cucumber ...

Then the parallel_test is group leader and Process.getpgid(child_pid) == Process.pid, so the signal is swallowed.

One workaround is:

run: |
   handle_signal() {
     kill -INT $child_pid
   }
   trap handle_signal SIGINT
   bundle exec parallel_cucumber .. &
   child_pid=$?

Now the runner shell remains the group leader and the check passes -- it's kind of a bother though :). There's a lot of discussion about how github could do better, but here we are.

This changes the check to use tty? - which itself can be wrong (redirects in shell or command runners). This feels like the sort of thing where someone will always be unhappy, unfortunately. Could add an envvar as an escape hatch?

Checklist

grosser commented 2 months ago

don't really want to mess with that logic since it has a history of having weird edge-cases and it was pretty stable since the last change, so would prefer an env-var escape hatch instead

timreinke commented 2 months ago

Yeah, I don't think I'd want to step into that one either :)

I switched to using an envvar, and can update the PR title/desc + add a small note in the README if you think this is worth getting in.

On my end, I've ended up finding it's better to install an interrupt handler in the top-level shell process, and send SIGINT directly to the test runners. Trying to get everything between to propagate and behave nicely turned out a bit of a fool's errand. So I'm just as happy to close this.

grosser commented 2 months ago

thx for digging into this mess, let's close it until someone else comes around that needs it then :)