spec/queues_spec.rb in resque-dynamic-queues-0.5.1 vs spec/queues_spec.rb in resque-dynamic-queues-0.6.0
- old
+ new
@@ -50,11 +50,11 @@
end
it "should pass lint" do
Resque::Plugin.lint(Resque::Plugins::DynamicQueues)
end
-
+
end
context "basic queue patterns" do
before(:each) do
@@ -78,11 +78,11 @@
end
it "can include queues with pattern"do
worker = Resque::Worker.new("high*")
worker.queues.should == ["high_x", "high_y"]
-
+
worker = Resque::Worker.new("*high_z")
worker.queues.should == ["superhigh_z"]
worker = Resque::Worker.new("*high*")
worker.queues.should == ["high_x", "high_y", "superhigh_z"]
@@ -106,10 +106,20 @@
Resque.set_dynamic_queue("mykey", ["foo", "bar"])
worker = Resque::Worker.new("@mykey")
worker.queues.should == ["bar", "foo"]
end
+ it "will not bloat the workers queue" do
+ Resque.watch_queue("high_x")
+ worker = Resque::Worker.new("@mykey")
+
+ worker.send(:instance_eval, "@queues").should == ['@mykey']
+ worker.queues.should == ["high_x"]
+ worker.send(:instance_eval, "@queues").should == ['@mykey']
+ worker.queues.should == ["high_x"]
+ end
+
it "uses hostname as default key in dynamic queues" do
host = `hostname`.chomp
Resque.set_dynamic_queue(host, ["foo", "bar"])
worker = Resque::Worker.new("@")
worker.queues.should == ["bar", "foo"]
@@ -118,14 +128,36 @@
it "can use wildcards in dynamic queues" do
Resque.watch_queue("high_x")
Resque.watch_queue("foo")
Resque.watch_queue("high_y")
Resque.watch_queue("superhigh_z")
-
+
Resque.set_dynamic_queue("mykey", ["*high*", "!high_y"])
worker = Resque::Worker.new("@mykey")
worker.queues.should == ["high_x", "superhigh_z"]
end
-
+
+ it "falls back to default queues when missing" do
+ Resque.set_dynamic_queue("default", ["foo", "bar"])
+ worker = Resque::Worker.new("@mykey")
+ worker.queues.should == ["bar", "foo"]
+ end
+
+ it "falls back to all queues when missing and no default" do
+ Resque.watch_queue("high_x")
+ Resque.watch_queue("foo")
+ worker = Resque::Worker.new("@mykey")
+ worker.queues.should == ["foo", "high_x"]
+ end
+
+ it "falls back to all queues when missing and no default and keep up to date" do
+ Resque.watch_queue("high_x")
+ Resque.watch_queue("foo")
+ worker = Resque::Worker.new("@mykey")
+ worker.queues.should == ["foo", "high_x"]
+ Resque.watch_queue("bar")
+ worker.queues.should == ["bar", "foo", "high_x"]
+ end
+
end
end