spec/hotseat/queue_spec.rb in hotseat-0.6.0 vs spec/hotseat/queue_spec.rb in hotseat-0.7.0
- old
+ new
@@ -18,10 +18,17 @@
# Returns the new doc id's
def create_some_docs(n=3)
(1..n).map {|i| DB.save_doc(sample_doc(i))['id'] }
end
+ # Returns unsaved new docs
+ def create_new_docs(n=3)
+ docs=[]
+ (1..n).each {|i| docs<<sample_doc(i)}
+ docs
+ end
+
def enqueue(doc_ids)
@q.add_bulk doc_ids
end
describe "#initialize" do
@@ -166,10 +173,21 @@
DB.get(doc_id).should have_key(@q.config[:object_name])
end
end
end
+ describe "#create_and_add_bulk" do
+ it "should add multiple documents in bulk, given multiple new docs" do
+ reset_test_queue!
+ docs = create_new_docs
+ result=@q.create_and_add_bulk docs
+ result.each do |row|
+ DB.get(row["id"]).should have_key(@q.config[:object_name])
+ end
+ end
+ end
+
describe "#num_pending" do
it "should return the number of documents available for lease" do
reset_test_queue!
enqueue( create_some_docs(3) )
@q.num_pending.should == 3
@@ -348,9 +366,27 @@
docs = rem_ids.map{|id| @q.db.get(id) }
docs.each {|doc| @q.db.delete_doc(doc) }
res = @q.unlease_bulk @doc_ids
res['errors'].should have(2).errors
res['errors'].map{|err| err['id']}.should == rem_ids
+ end
+ end
+
+ describe "#unlease_all" do
+ before(:each) do
+ reset_test_queue!
+ enqueue( create_some_docs(10) )
+ @leased = @q.lease 8
+ @doc_ids = @leased.map{|doc| doc['_id'] }
+ end
+
+ it "should unlock all leased documents" do
+ @q.unlease_all
+ docs = DB.get_bulk(@doc_ids)['rows'].map{|row| row['doc']}
+ docs.each do |doc|
+ doc.should have_key(@q.config[:object_name])
+ doc[@q.config[:object_name]].should_not have_key('lock')
+ end
end
end
describe "#remove" do
before(:each) do