Skip to content

Commit

Permalink
Add more explicit offline/online publisher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Trubach authored and michaelklishin committed Jan 24, 2025
1 parent 8f1b066 commit 02cfd77
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion spec/sneakers/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
exchange = Object.new
existing_session = Bunny.new

mock(existing_session).start { existing_session }
mock(existing_session).start
mock(existing_session).create_channel { channel }

mock(channel).exchange('another_exchange', type: :topic, durable: false, :auto_delete => false, arguments: { 'x-arg' => 'value' }) do
Expand All @@ -122,6 +122,8 @@
durable: false
)
@existing_session = existing_session
@exchange = exchange
@channel = channel
end

it 'can handle an existing connection object' do
Expand All @@ -136,6 +138,29 @@
p.publish('test msg', my_vars)
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
end

it 'can handle an existing connection that is online' do
p = Sneakers::Publisher.new
p.publish('test msg', my_vars)
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
mock(@existing_session).connected? { true }
mock(@exchange).publish('test msg 2', my_vars)
p.publish('test msg 2', my_vars)
end

it 'can handle an existing connection that goes offline' do
p = Sneakers::Publisher.new
p.publish('test msg', my_vars)
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
mock(@existing_session).connected? { false }
mock(@existing_session).start
mock(@existing_session).create_channel { @channel }
mock(@channel).exchange('another_exchange', type: :topic, durable: false, :auto_delete => false, arguments: { 'x-arg' => 'value' }) do
@exchange
end
mock(@exchange).publish('test msg 2', my_vars)
p.publish('test msg 2', my_vars)
end
end

it 'should publish using the content type serializer' do
Expand Down

0 comments on commit 02cfd77

Please sign in to comment.