Skip to content

Commit b0c7093

Browse files
committed
skip forking tests for jruby
1 parent 55e9717 commit b0c7093

File tree

3 files changed

+67
-63
lines changed

3 files changed

+67
-63
lines changed

test/connection_pool_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module Resque
5959
end
6060

6161
it 'is fork aware' do
62+
skip if jruby?
6263
cp = ConnectionPool.new(REDIS_URL, 1)
6364
conn = cp.checkout
6465

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,7 @@ def now
136136

137137
self.fake_time = nil
138138
end
139+
140+
def jruby?
141+
defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
142+
end

test/worker_test.rb

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -468,75 +468,74 @@ def self.perform
468468
refute_equal original_connection, Resque.redis.client.connection.instance_variable_get("@sock")
469469
end
470470

471-
if !defined?(RUBY_ENGINE) || defined?(RUBY_ENGINE) && RUBY_ENGINE != "jruby"
472-
[SignalException, Resque::TermException].each do |exception|
473-
{
474-
'cleanup occurs in allotted time' => nil,
475-
'cleanup takes too long' => 2
476-
}.each do |scenario,rescue_time|
477-
it "SIGTERM when #{scenario} while catching #{exception}" do
478-
begin
479-
eval("class LongRunningJob; @@exception = #{exception}; end")
480-
class LongRunningJob
481-
@queue = :long_running_job
482-
483-
def self.perform( run_time, rescue_time=nil )
484-
Resque.redis.client.reconnect # get its own connection
485-
Resque.redis.rpush( 'sigterm-test:start', Process.pid )
486-
sleep run_time
487-
Resque.redis.rpush( 'sigterm-test:result', 'Finished Normally' )
488-
rescue @@exception => e
489-
Resque.redis.rpush( 'sigterm-test:result', %Q(Caught SignalException: #{e.inspect}))
490-
sleep rescue_time unless rescue_time.nil?
491-
ensure
492-
Resque.redis.rpush( 'sigterm-test:final', 'exiting.' )
493-
end
471+
[SignalException, Resque::TermException].each do |exception|
472+
{
473+
'cleanup occurs in allotted time' => nil,
474+
'cleanup takes too long' => 2
475+
}.each do |scenario,rescue_time|
476+
it "SIGTERM when #{scenario} while catching #{exception}" do
477+
skip if jruby?
478+
begin
479+
eval("class LongRunningJob; @@exception = #{exception}; end")
480+
class LongRunningJob
481+
@queue = :long_running_job
482+
483+
def self.perform( run_time, rescue_time=nil )
484+
Resque.redis.client.reconnect # get its own connection
485+
Resque.redis.rpush( 'sigterm-test:start', Process.pid )
486+
sleep run_time
487+
Resque.redis.rpush( 'sigterm-test:result', 'Finished Normally' )
488+
rescue @@exception => e
489+
Resque.redis.rpush( 'sigterm-test:result', %Q(Caught SignalException: #{e.inspect}))
490+
sleep rescue_time unless rescue_time.nil?
491+
ensure
492+
Resque.redis.rpush( 'sigterm-test:final', 'exiting.' )
494493
end
494+
end
495495

496-
Resque.enqueue( LongRunningJob, 5, rescue_time )
497-
498-
worker_pid = Kernel.fork do
499-
# ensure we actually fork
500-
$TESTING = false
501-
# reconnect since we just forked
502-
Resque.redis.client.reconnect
496+
Resque.enqueue( LongRunningJob, 5, rescue_time )
503497

504-
worker = Resque::Worker.new(:long_running_job)
505-
worker.term_timeout = 1
498+
worker_pid = Kernel.fork do
499+
# ensure we actually fork
500+
$TESTING = false
501+
# reconnect since we just forked
502+
Resque.redis.client.reconnect
506503

507-
worker.work(0)
508-
exit!
509-
end
504+
worker = Resque::Worker.new(:long_running_job)
505+
worker.term_timeout = 1
510506

511-
# ensure the worker is started
512-
start_status = Resque.redis.blpop( 'sigterm-test:start', 5 )
513-
refute_nil start_status
514-
child_pid = start_status[1].to_i
515-
assert_operator child_pid, :>, 0
516-
517-
# send signal to abort the worker
518-
Process.kill('TERM', worker_pid)
519-
Process.waitpid(worker_pid)
520-
521-
# wait to see how it all came down
522-
result = Resque.redis.blpop( 'sigterm-test:result', 5 )
523-
refute_nil result
524-
assert !result[1].start_with?('Finished Normally'), 'Job Finished normally. Sleep not long enough?'
525-
assert result[1].start_with? 'Caught SignalException', 'Signal exception not raised in child.'
526-
527-
# ensure that the child pid is no longer running
528-
child_still_running = !(`ps -p #{child_pid.to_s} -o pid=`).empty?
529-
assert !child_still_running
530-
531-
# see if post-cleanup occurred. This should happen IFF the rescue_time is less than the term_timeout
532-
post_cleanup_occurred = Resque.redis.lpop( 'sigterm-test:final' )
533-
assert post_cleanup_occurred, 'post cleanup did not occur. SIGKILL sent too early?' if rescue_time.nil?
534-
assert !post_cleanup_occurred, 'post cleanup occurred. SIGKILL sent too late?' unless rescue_time.nil?
535-
536-
ensure
537-
remaining_keys = Resque.redis.keys('sigterm-test:*') || []
538-
Resque.redis.del(*remaining_keys) unless remaining_keys.empty?
507+
worker.work(0)
508+
exit!
539509
end
510+
511+
# ensure the worker is started
512+
start_status = Resque.redis.blpop( 'sigterm-test:start', 5 )
513+
refute_nil start_status
514+
child_pid = start_status[1].to_i
515+
assert_operator child_pid, :>, 0
516+
517+
# send signal to abort the worker
518+
Process.kill('TERM', worker_pid)
519+
Process.waitpid(worker_pid)
520+
521+
# wait to see how it all came down
522+
result = Resque.redis.blpop( 'sigterm-test:result', 5 )
523+
refute_nil result
524+
assert !result[1].start_with?('Finished Normally'), 'Job Finished normally. Sleep not long enough?'
525+
assert result[1].start_with? 'Caught SignalException', 'Signal exception not raised in child.'
526+
527+
# ensure that the child pid is no longer running
528+
child_still_running = !(`ps -p #{child_pid.to_s} -o pid=`).empty?
529+
assert !child_still_running
530+
531+
# see if post-cleanup occurred. This should happen IFF the rescue_time is less than the term_timeout
532+
post_cleanup_occurred = Resque.redis.lpop( 'sigterm-test:final' )
533+
assert post_cleanup_occurred, 'post cleanup did not occur. SIGKILL sent too early?' if rescue_time.nil?
534+
assert !post_cleanup_occurred, 'post cleanup occurred. SIGKILL sent too late?' unless rescue_time.nil?
535+
536+
ensure
537+
remaining_keys = Resque.redis.keys('sigterm-test:*') || []
538+
Resque.redis.del(*remaining_keys) unless remaining_keys.empty?
540539
end
541540
end
542541
end

0 commit comments

Comments
 (0)