@@ -147,6 +147,10 @@ def @amqp_client.connected?; false; end # stubbing predicate methods not working
147147 @publisher . reset!
148148 end
149149
150+ after do
151+ @publisher . disconnected!
152+ end
153+
150154 it "is a singleton" do
151155 lambda { Chef ::IndexQueue ::Indexable ::AmqpClient . new } . should raise_error
152156 end
@@ -174,11 +178,35 @@ def @amqp_client.connected?; false; end # stubbing predicate methods not working
174178 @publisher . exchange . should == @exchange
175179 end
176180
177- it "publishes an action to the exchange" do
178- @amqp_client . stub! ( :qos )
179- data = { "some_data" => "in_a_hash" }
180- @exchange . should_receive ( :publish ) . with ( { "action" => "hot_chef_on_queue" , "payload" => data } . to_json )
181- @publisher . send_action ( :hot_chef_on_queue , data )
181+ describe "publishing" do
182+ before do
183+ @amqp_client . stub! ( :qos )
184+ @data = { "some_data" => "in_a_hash" }
185+ end
186+
187+ it "publishes an action to the exchange" do
188+ @exchange . should_receive ( :publish ) . with ( { "action" => "hot_chef_on_queue" , "payload" => @data } . to_json )
189+ @publisher . send_action ( :hot_chef_on_queue , @data )
190+ end
191+
192+ it "resets the client upon a Bunny::ServerDownError when publishing" do
193+ @exchange . should_receive ( :publish ) . and_raise ( Bunny ::ServerDownError )
194+ @publisher . should_receive ( :disconnected! ) . twice
195+ lambda { @publisher . send_action ( :hot_chef_on_queue , @data ) } . should raise_error ( Bunny ::ServerDownError )
196+ end
197+
198+ it "resets the client upon a Bunny::ConnectionError when publishing" do
199+ @exchange . should_receive ( :publish ) . and_raise ( Bunny ::ConnectionError )
200+ @publisher . should_receive ( :disconnected! ) . twice
201+ lambda { @publisher . send_action ( :hot_chef_on_queue , @data ) } . should raise_error ( Bunny ::ConnectionError )
202+ end
203+
204+ it "resets the client upon a Errno::ECONNRESET when publishing" do
205+ @exchange . should_receive ( :publish ) . and_raise ( Errno ::ECONNRESET )
206+ @publisher . should_receive ( :disconnected! ) . twice
207+ lambda { @publisher . send_action ( :hot_chef_on_queue , @data ) } . should raise_error ( Errno ::ECONNRESET )
208+ end
209+
182210 end
183211
184212 it "creates a queue bound to its exchange with a temporary UUID" do
0 commit comments