spec/lib/consumer_spec.rb in vx-consumer-0.1.2 vs spec/lib/consumer_spec.rb in vx-consumer-0.1.3

- old
+ new

@@ -2,10 +2,14 @@ require 'timeout' require 'spec_helper' describe Vx::Consumer do + before do + Bob.timeout = 0.1 + end + context "test consumer declaration" do context "alice" do subject { Alice.params } its(:exchange_name) { should eq 'amq.fanout' } its(:exchange_options) { should eq(durable: true, auto_delete: false, type: :fanout) } @@ -20,11 +24,11 @@ context "bob" do subject { Bob.params } its(:exchange_name) { should eq 'bob_exch' } its(:exchange_options) { should eq(durable: false, auto_delete: true, type: :topic) } its(:queue_name) { should eq 'bob_queue' } - its(:queue_options) { should eq(exclusive: true, durable: false) } + its(:queue_options) { should eq(durable: false, auto_delete: true) } its(:ack) { should be_true } its(:routing_key) { should be_nil } its(:content_type) { should eq 'application/json' } end end @@ -58,11 +62,11 @@ end end Timeout.timeout(10) do loop do - break if Bob._collected.size == 90 + break if Bob._collected.size >= 90 sleep 0.1 end end cns.map(&:cancel) @@ -105,24 +109,27 @@ expect(Bob._collected.map(&:values).flatten.sort).to eq [1,2] end it "should work with graceful shutdown" do + Bob.timeout = 1 + consumer = Bob.subscribe 10.times do |n| Bob.publish a: n end - sleep 0.2 - Timeout.timeout(1) do + sleep 0.1 + Timeout.timeout(5) do consumer.graceful_shutdown end - expect(Bob._collected).to have_at_least(2).item + expect(Bob._collected).to_not be_empty end it "running? should be true when consumer process task" do + Bob.timeout = 1 consumer = Bob.subscribe expect(consumer.running?).to be_false 10.times do |n| @@ -134,9 +141,10 @@ Timeout.timeout(1) do consumer.cancel end + sleep 0.1 expect(consumer.running?).to be_false end def handle_errors begin