Permalink
Browse files

Added spec for Job.clear_locks!

  • Loading branch information...
1 parent 21610e5 commit 81a09e1fc4bf7c52d68f422f8b25448d23a7e7ed @bkeepers bkeepers committed Jan 2, 2010
Showing with 20 additions and 6 deletions.
  1. +20 −6 spec/shared_backend_spec.rb
@@ -1,4 +1,8 @@
shared_examples_for 'a backend' do
+ def create_job(opts = {})
+ @backend.create(opts.merge(:payload_object => SimpleJob.new))
+ end
+
before do
SimpleJob.runs = 0
end
@@ -68,10 +72,6 @@
end
describe "find_available" do
- def create_job(opts = {})
- @backend.create(opts.merge(:payload_object => SimpleJob.new))
- end
-
it "should not find failed jobs" do
@job = create_job :attempts => 50, :failed_at => @backend.db_time_now
@backend.find_available('worker', 5, 1.second).should_not include(@job)
@@ -177,7 +177,6 @@ def create_job(opts = {})
end
context "worker prioritization" do
-
before(:each) do
Delayed::Worker.max_priority = nil
Delayed::Worker.min_priority = nil
@@ -196,7 +195,22 @@ def create_job(opts = {})
}
ordered.should == true
end
-
+ end
+
+ context "clear_locks!" do
+ before do
+ @job = create_job(:locked_by => 'worker', :locked_at => @backend.db_time_now)
+ end
+
+ it "should clear locks for the given worker" do
+ @backend.clear_locks!('worker')
+ @backend.find_available('worker2', 5, 1.minute).should include(@job)
+ end
+
+ it "should not clear locks for other workers" do
+ @backend.clear_locks!('worker1')
+ @backend.find_available('worker1', 5, 1.minute).should_not include(@job)
+ end
end
end

0 comments on commit 81a09e1

Please sign in to comment.