@@ -438,74 +438,76 @@ def self.perform
438
438
assert_not_equal original_connection , Resque . redis . client . connection . instance_variable_get ( "@sock" )
439
439
end
440
440
441
- [ SignalException , Resque ::TermException ] . each do |exception |
442
- {
443
- 'cleanup occurs in allotted time' => nil ,
444
- 'cleanup takes too long' => 2
445
- } . each do |scenario , rescue_time |
446
- test "SIGTERM when #{ scenario } while catching #{ exception } " do
447
- begin
448
- eval ( "class LongRunningJob; @@exception = #{ exception } ; end" )
449
- class LongRunningJob
450
- @queue = :long_running_job
451
-
452
- def self . perform ( run_time , rescue_time = nil )
453
- Resque . redis . client . reconnect # get its own connection
454
- Resque . redis . rpush ( 'sigterm-test:start' , Process . pid )
455
- sleep run_time
456
- Resque . redis . rpush ( 'sigterm-test:result' , 'Finished Normally' )
457
- rescue @@exception => e
458
- Resque . redis . rpush ( 'sigterm-test:result' , %Q(Caught SignalException: #{ e . inspect } ) )
459
- sleep rescue_time unless rescue_time . nil?
460
- ensure
461
- Resque . redis . rpush ( 'sigterm-test:final' , 'exiting.' )
441
+ if !defined? ( RUBY_ENGINE ) || defined? ( RUBY_ENGINE ) && RUBY_ENGINE != "jruby"
442
+ [ SignalException , Resque ::TermException ] . each do |exception |
443
+ {
444
+ 'cleanup occurs in allotted time' => nil ,
445
+ 'cleanup takes too long' => 2
446
+ } . each do |scenario , rescue_time |
447
+ test "SIGTERM when #{ scenario } while catching #{ exception } " do
448
+ begin
449
+ eval ( "class LongRunningJob; @@exception = #{ exception } ; end" )
450
+ class LongRunningJob
451
+ @queue = :long_running_job
452
+
453
+ def self . perform ( run_time , rescue_time = nil )
454
+ Resque . redis . client . reconnect # get its own connection
455
+ Resque . redis . rpush ( 'sigterm-test:start' , Process . pid )
456
+ sleep run_time
457
+ Resque . redis . rpush ( 'sigterm-test:result' , 'Finished Normally' )
458
+ rescue @@exception => e
459
+ Resque . redis . rpush ( 'sigterm-test:result' , %Q(Caught SignalException: #{ e . inspect } ) )
460
+ sleep rescue_time unless rescue_time . nil?
461
+ ensure
462
+ Resque . redis . rpush ( 'sigterm-test:final' , 'exiting.' )
463
+ end
462
464
end
463
- end
464
465
465
- Resque . enqueue ( LongRunningJob , 5 , rescue_time )
466
+ Resque . enqueue ( LongRunningJob , 5 , rescue_time )
466
467
467
- worker_pid = Kernel . fork do
468
- # ensure we actually fork
469
- $TESTING = false
470
- # reconnect since we just forked
471
- Resque . redis . client . reconnect
468
+ worker_pid = Kernel . fork do
469
+ # ensure we actually fork
470
+ $TESTING = false
471
+ # reconnect since we just forked
472
+ Resque . redis . client . reconnect
472
473
473
- worker = Resque ::Worker . new ( :long_running_job )
474
- worker . term_timeout = 1
475
- worker . term_child = 1
474
+ worker = Resque ::Worker . new ( :long_running_job )
475
+ worker . term_timeout = 1
476
+ worker . term_child = 1
476
477
477
- worker . work ( 0 )
478
- exit!
479
- end
478
+ worker . work ( 0 )
479
+ exit!
480
+ end
480
481
481
- # ensure the worker is started
482
- start_status = Resque . redis . blpop ( 'sigterm-test:start' , 5 )
483
- assert_not_nil start_status
484
- child_pid = start_status [ 1 ] . to_i
485
- assert_operator child_pid , :> , 0
486
-
487
- # send signal to abort the worker
488
- Process . kill ( 'TERM' , worker_pid )
489
- Process . waitpid ( worker_pid )
490
-
491
- # wait to see how it all came down
492
- result = Resque . redis . blpop ( 'sigterm-test:result' , 5 )
493
- assert_not_nil result
494
- assert !result [ 1 ] . start_with? ( 'Finished Normally' ) , 'Job Finished normally. Sleep not long enough?'
495
- assert result [ 1 ] . start_with? 'Caught SignalException' , 'Signal exception not raised in child.'
496
-
497
- # ensure that the child pid is no longer running
498
- child_still_running = !( `ps -p #{ child_pid . to_s } -o pid=` ) . empty?
499
- assert !child_still_running
500
-
501
- # see if post-cleanup occurred. This should happen IFF the rescue_time is less than the term_timeout
502
- post_cleanup_occurred = Resque . redis . lpop ( 'sigterm-test:final' )
503
- assert post_cleanup_occurred , 'post cleanup did not occur. SIGKILL sent too early?' if rescue_time . nil?
504
- assert !post_cleanup_occurred , 'post cleanup occurred. SIGKILL sent too late?' unless rescue_time . nil?
505
-
506
- ensure
507
- remaining_keys = Resque . redis . keys ( 'sigterm-test:*' ) || [ ]
508
- Resque . redis . del ( *remaining_keys ) unless remaining_keys . empty?
482
+ # ensure the worker is started
483
+ start_status = Resque . redis . blpop ( 'sigterm-test:start' , 5 )
484
+ assert_not_nil start_status
485
+ child_pid = start_status [ 1 ] . to_i
486
+ assert_operator child_pid , :> , 0
487
+
488
+ # send signal to abort the worker
489
+ Process . kill ( 'TERM' , worker_pid )
490
+ Process . waitpid ( worker_pid )
491
+
492
+ # wait to see how it all came down
493
+ result = Resque . redis . blpop ( 'sigterm-test:result' , 5 )
494
+ assert_not_nil result
495
+ assert !result [ 1 ] . start_with? ( 'Finished Normally' ) , 'Job Finished normally. Sleep not long enough?'
496
+ assert result [ 1 ] . start_with? 'Caught SignalException' , 'Signal exception not raised in child.'
497
+
498
+ # ensure that the child pid is no longer running
499
+ child_still_running = !( `ps -p #{ child_pid . to_s } -o pid=` ) . empty?
500
+ assert !child_still_running
501
+
502
+ # see if post-cleanup occurred. This should happen IFF the rescue_time is less than the term_timeout
503
+ post_cleanup_occurred = Resque . redis . lpop ( 'sigterm-test:final' )
504
+ assert post_cleanup_occurred , 'post cleanup did not occur. SIGKILL sent too early?' if rescue_time . nil?
505
+ assert !post_cleanup_occurred , 'post cleanup occurred. SIGKILL sent too late?' unless rescue_time . nil?
506
+
507
+ ensure
508
+ remaining_keys = Resque . redis . keys ( 'sigterm-test:*' ) || [ ]
509
+ Resque . redis . del ( *remaining_keys ) unless remaining_keys . empty?
510
+ end
509
511
end
510
512
end
511
513
end
0 commit comments