rspec/rspec-core

RSpec skipping at_exit hooks on force quit

semaperepelitsa opened this issue · 1 comments

This is a follow-up to this rejected PR: #2490

We also had issue with RSpec skipping at_exit hooks when interrupting specs. I thought our example might give you a better illustration of why it is such a big problem.

We use RSpec in a large Rails app for all kinds of specs, including high level browser specs with Capybara and Selenium. Those specs are inherently much slower than model specs, commonly passing 10 seconds each, with the whole suite taking more than a minute.

What would happen is that I run the suite, see a few errors and want to abort the process. When I press Ctrl-C, it still takes 10 more seconds to finish the current spec, which I don't care about. So I press Ctrl-C again to exit immediately. However, now I end up with zombie browser processes because at_exit hooks were skipped so Capybara wasn't able to do its cleanup. In the end, I either need to clean them up manually or wait those 10 extra seconds next time.

We have been running a patched version of RSpec that always runs at_exit hooks on interrupt for more than 2 years now, and experienced zero drawbacks to this behavior. Is it possible to include this in core RSpec, at least an an option?

I've changed the title here because we don't skip at_exit hooks on interupt, thats why we have the whole "waiting to finish" mode, we do skip at_exit hooks on force quit (double interupt), which is intended to be a "I meant it" mode, including skipping at_exit hooks which may have broken or are otherwise holding up quitting.

Really if there are zombie processes left over from a force quit this it is a result of using the "emergency" exit something that shouldn't be a usual habit, if you have tests taking 10 seconds! to finish thats the problem for which this is a symptom.

If you need to run a focused set of tests we have numerous filters and other helpers to make that so, we also have a configurable "fail fast" mode to quit after a number of failures.

That said if you want to really want to open a PR to configure this [not as a default] I would review a PR if the name is something like: wait_for_at_exit_hooks_in_force_quit, includes the usual specs for config, and would require scenario for our cucumber documentation. In the mean time I will add a note to the output highlighting this is a force quit and will skip such hooks.

Additionally the reason why we catch and delay exiting at all, is to allow cleanup via our hooks to complete, we need to let examples finish to allow after and around hooks to complete their cleanup. So really you could end up with weird states regardless of wether we use exit or exit!.

Closing as duplicate but as above, if you want to open a PR I'll review it.