Skip to content

Commit 3f67df5

Browse files
committed
Merge pull request resque#717 from kjwierenga/feature/spec-conditional-fork-hooks
Specs for conditional fork hooks - completes forward porting to 2.0 (master) branch
2 parents 923fda3 + ffd9f47 commit 3f67df5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/worker_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,19 @@ def self.perform
450450
assert $BEFORE_FORK_CALLED == workerA.will_fork?
451451
end
452452

453+
it "Will not call a before_fork hook when the worker can't fork" do
454+
Resque.redis.flushall
455+
$BEFORE_FORK_CALLED = false
456+
Resque.before_fork = Proc.new { $BEFORE_FORK_CALLED = true }
457+
workerA = Resque::Worker.new(:jobs)
458+
workerA.cant_fork = true
459+
460+
assert !$BEFORE_FORK_CALLED, "before_fork should not have been called before job runs"
461+
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
462+
workerA.work(0)
463+
assert !$BEFORE_FORK_CALLED, "before_fork should not have been called after job runs"
464+
end
465+
453466
it "Will not call a before_fork hook when the worker can't fork" do
454467
Resque.redis.flushall
455468
$BEFORE_FORK_CALLED = false
@@ -507,6 +520,19 @@ def self.perform
507520
assert !$AFTER_FORK_CALLED
508521
end
509522

523+
it "Will not call an after_fork hook when the worker can't fork" do
524+
Resque.redis.flushall
525+
$AFTER_FORK_CALLED = false
526+
Resque.after_fork = Proc.new { $AFTER_FORK_CALLED = true }
527+
workerA = Resque::Worker.new(:jobs)
528+
workerA.cant_fork = true
529+
530+
assert !$AFTER_FORK_CALLED
531+
Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
532+
workerA.work(0)
533+
assert !$AFTER_FORK_CALLED
534+
end
535+
510536
it "returns PID of running process" do
511537
assert_equal @worker.to_s.split(":")[1].to_i, @worker.pid
512538
end

0 commit comments

Comments
 (0)