Permalink
Browse files

New test case for job with one concurrent

  • Loading branch information...
1 parent 028822a commit 7a7d7a2e316cd0616823927fa9471368ac936597 @unlimit committed Apr 17, 2012
Showing with 49 additions and 0 deletions.
  1. +37 −0 spec/resque_worker_extensions_spec.rb
  2. +12 −0 spec/spec_helper.rb
@@ -178,6 +178,43 @@
MultipleConcurrentRestrictionJob.total_run_count.should == 7
end
+ it "should run only one concurrent job" do
+ 5.times {|i| Resque.enqueue(OneConcurrentRestrictionJob, i) }
+ 5.times do
+ unless child = fork
+ Resque.redis.client.connect
+ run_resque_queue('*')
+ exit!
+ end
+ end
+ sleep 0.25
+
+ OneConcurrentRestrictionJob.total_run_count.should == 1
+ OneConcurrentRestrictionJob.running_count(OneConcurrentRestrictionJob.tracking_key).should == 1
+ OneConcurrentRestrictionJob.restriction_queue(OneConcurrentRestrictionJob.tracking_key, :normal).size.should == 4
+
+ Process.waitall
+
+ 2.times do
+ unless child = fork
+ Resque.redis.client.connect
+ run_resque_queue('*')
+ exit!
+ end
+ end
+ sleep 0.25
+
+ OneConcurrentRestrictionJob.total_run_count.should == 2
+ OneConcurrentRestrictionJob.running_count(OneConcurrentRestrictionJob.tracking_key).should == 1
+ OneConcurrentRestrictionJob.restriction_queue(OneConcurrentRestrictionJob.tracking_key, :normal).size.should == 3
+
+ Process.waitall
+
+ OneConcurrentRestrictionJob.running_count(OneConcurrentRestrictionJob.tracking_key).should == 0
+ OneConcurrentRestrictionJob.total_run_count.should == 2
+
+ end
+
it "should decrement execution number when concurrent job fails" do
run_resque_job(ConcurrentRestrictionJob, "bad")
Resque.redis.lrange("failed", 0, -1).size.should == 1
View
@@ -167,3 +167,15 @@ def self.perform(*args)
sleep 0.5
end
end
+
+class OneConcurrentRestrictionJob
+ extend RunCountHelper
+ extend Resque::Plugins::ConcurrentRestriction
+ concurrent 1
+
+ @queue = 'normal'
+
+ def self.perform(*args)
+ sleep 0.5
+ end
+end

0 comments on commit 7a7d7a2

Please sign in to comment.