Permalink
Browse files

Added missing tests and pause attr_writers.

  • Loading branch information...
1 parent 842e6e6 commit 2c2f1d0c5ecb0eeb260649444ac5002e3759f8e7 @panthomakos panthomakos committed Sep 25, 2012
Showing with 53 additions and 13 deletions.
  1. +8 −4 lib/resque.rb
  2. +45 −9 test/resque_hook_test.rb
View
@@ -132,17 +132,21 @@ def before_pause(&block)
block ? register_hook(:before_pause, block) : hooks(:before_pause)
end
- # Set the after_pause proc.
- attr_writer :before_pause
+ # Register a before_pause proc.
+ def before_pause=(block)
+ register_hook(:before_pause, block)
+ end
# The `after_pause` hook will be run in the parent process after the
# worker has paused (via SIGCONT).
def after_pause(&block)
block ? register_hook(:after_pause, block) : hooks(:after_pause)
end
- # Set the after_continue proc.
- attr_writer :after_pause
+ # Register an after_pause proc.
+ def after_pause=(block)
+ register_hook(:after_pause, block)
+ end
def to_s
"Resque Client connected to #{redis_id}"
View
@@ -25,7 +25,7 @@ def self.perform
assert_equal [], Resque.after_fork
end
- it 'it calls before_first_fork once' do
+ it 'calls before_first_fork once' do
counter = 0
Resque.before_first_fork { counter += 1 }
@@ -36,7 +36,7 @@ def self.perform
assert_equal(1, counter)
end
- it 'it calls before_fork before each job' do
+ it 'calls before_fork before each job' do
counter = 0
Resque.before_fork { counter += 1 }
@@ -47,7 +47,7 @@ def self.perform
assert_equal(2, counter)
end
- it 'it calls after_fork after each job' do
+ it 'calls after_fork after each job' do
counter = 0
Resque.after_fork { counter += 1 }
@@ -58,28 +58,28 @@ def self.perform
assert_equal(2, counter)
end
- it 'it calls before_first_fork before forking' do
+ it 'calls before_first_fork before forking' do
Resque.before_first_fork { assert(!$called) }
Resque::Job.create(:jobs, CallNotifyJob)
@worker.work(0)
end
- it 'it calls before_fork before forking' do
+ it 'calls before_fork before forking' do
Resque.before_fork { assert(!$called) }
Resque::Job.create(:jobs, CallNotifyJob)
@worker.work(0)
end
- it 'it calls after_fork after forking' do
+ it 'calls after_fork after forking' do
Resque.after_fork { assert($called) }
Resque::Job.create(:jobs, CallNotifyJob)
@worker.work(0)
end
- it 'it registeres multiple before_first_forks' do
+ it 'registeres multiple before_first_forks' do
first = false
second = false
@@ -92,7 +92,7 @@ def self.perform
assert(first && second)
end
- it 'it registers multiple before_forks' do
+ it 'registers multiple before_forks' do
first = false
second = false
@@ -105,7 +105,7 @@ def self.perform
assert(first && second)
end
- it 'it registers multiple after_forks' do
+ it 'registers multiple after_forks' do
first = false
second = false
@@ -117,4 +117,40 @@ def self.perform
@worker.work(0)
assert(first && second)
end
+
+ it 'registers multiple before_pause hooks' do
+ first = false
+ second = false
+
+ Resque.before_pause { first = true }
+ Resque.before_pause { second = true }
+
+ @worker.pause_processing
+
+ assert(!first && !second)
+
+ t = Thread.start { sleep(0.1); Process.kill('CONT', @worker.pid) }
+ @worker.work(0)
+ t.join
+
+ assert(first && second)
+ end
+
+ it 'registers multiple after_pause hooks' do
+ first = false
+ second = false
+
+ Resque.after_pause { first = true }
+ Resque.after_pause { second = true }
+
+ @worker.pause_processing
+
+ assert(!first && !second)
+
+ t = Thread.start { sleep(0.1); Process.kill('CONT', @worker.pid) }
+ @worker.work(0)
+ t.join
+
+ assert(first && second)
+ end
end

0 comments on commit 2c2f1d0

Please sign in to comment.