bacon/client.rb in brontes3d-amqp-0.6.4.3 vs bacon/client.rb in brontes3d-amqp-0.6.7.1
- old
+ new
@@ -1,7 +1,9 @@
# this is the bacon spec for AMQP client
# you can find other specs inline in frame.rb, buffer.rb and protocol.rb
+# to run just 1 test use:
+# bacon lib/amqp.rb --name "should ..."
# this one couldn't be written in line because:
# due to the load order 'AMQP' isn't completely defined yet when Client is loaded
require 'mocha'
describe Client do
@@ -12,10 +14,11 @@
Thread.current[:mq] = nil
AMQP.instance_eval{ @conn = nil }
AMQP.instance_eval{ @closing = false }
Client.class_eval{ @retry_count = 0 }
Client.class_eval{ @server_to_select = 0 }
+ EM.instance_eval{ @next_tick_queue = nil }
end
should 'reconnect on disconnect after connection_completed (use reconnect_timer)' do
@times_connected = 0
@connect_args = []
@@ -69,11 +72,11 @@
arg1.should == "nonexistanthost"
arg2.should == 5672
end
end
- should "use fallback servers on reconnect" do
+ should "use fallback servers on reconnect without connection_completed" do
@times_connected = 0
@connect_args = []
EventMachine.stubs(:connect_server).returns(99).with do |arg1, arg2|
@connect_args << [arg1, arg2]
@@ -287,9 +290,28 @@
true
end
EM.next_tick{ EM.add_timer(0.1){ EM.stop_event_loop } }
AMQP.start(:host => 'nonexistanthost')
@amqp_conn.should == @client
+ end
+
+ should "send Heartbeat frames based on keepalive interval" do
+ @stuff_sent = []
+ EventMachine.stubs(:connect_server).returns(99).with do |arg1, arg2|
+ EM.next_tick do
+ @client = EM.class_eval{ @conns }[99]
+ @amqp_conn = AMQP.class_eval{ @conn }
+ @client.stubs(:send).returns(true).with do |what_to_send|
+ @stuff_sent << what_to_send.class
+ true
+ end
+ @client.connection_completed
+ end
+ true
+ end
+ EM.next_tick{ EM.add_timer(0.5){ EM.stop_event_loop } }
+ AMQP.start(:host => 'nonexistanthost', :keepalive => 0.2)
+ @stuff_sent.should == [AMQP::Frame::Heartbeat, AMQP::Frame::Heartbeat]
end
end