resque/resque — pull request #1263 by benweint (2014-11-03 00:43:02+00:00)
Title: Don't run before_fork hooks if we aren't going to fork

**Note**: This change addresses the same issue as https://github.com/resque/resque/pull/1173, but I've taken @yaauie's suggestion of eliminating the `$TESTING` check from `will_fork?` and fixing the tests that were relying on it to instead explicitly use a new `without_forking` test helper to set `FORK_PER_JOB=false`.

I'm happy to adjust the approach to dealing with these tests if there's something else you had in mind, I just really want to get this fixed so that `FORK_PER_JOB` is usable.

When FORK_PER_JOB=false is set in the environment, Resque will not actually fork
for each job. Unfortunately, before_fork hooks will still run (although
after_fork hooks will not). This can lead to problems when the after_fork hook
has dependencies on the before_fork hook.

This change makes it so that before_fork hooks will no longer run when
FORK_PER_JOB=false.

I've also adjusted the conditions for the Worker#will_fork? method to ignore the
$TESTING global. Many of the worker tests were implicitly relying upon the fact
that forking would not happen during tests in order to work correctly, so those
tests have been changed to set FORK_PER_JOB=false in the environment instead,
via a new test helper, called without_forking.