Skip to content

Commit 02cfd77

Browse files
Ivan Trubachmichaelklishin
authored andcommitted
Add more explicit offline/online publisher tests
1 parent 8f1b066 commit 02cfd77

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spec/sneakers/publisher_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
exchange = Object.new
105105
existing_session = Bunny.new
106106

107-
mock(existing_session).start { existing_session }
107+
mock(existing_session).start
108108
mock(existing_session).create_channel { channel }
109109

110110
mock(channel).exchange('another_exchange', type: :topic, durable: false, :auto_delete => false, arguments: { 'x-arg' => 'value' }) do
@@ -122,6 +122,8 @@
122122
durable: false
123123
)
124124
@existing_session = existing_session
125+
@exchange = exchange
126+
@channel = channel
125127
end
126128

127129
it 'can handle an existing connection object' do
@@ -136,6 +138,29 @@
136138
p.publish('test msg', my_vars)
137139
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
138140
end
141+
142+
it 'can handle an existing connection that is online' do
143+
p = Sneakers::Publisher.new
144+
p.publish('test msg', my_vars)
145+
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
146+
mock(@existing_session).connected? { true }
147+
mock(@exchange).publish('test msg 2', my_vars)
148+
p.publish('test msg 2', my_vars)
149+
end
150+
151+
it 'can handle an existing connection that goes offline' do
152+
p = Sneakers::Publisher.new
153+
p.publish('test msg', my_vars)
154+
_(p.instance_variable_get(:@bunny)).must_equal @existing_session
155+
mock(@existing_session).connected? { false }
156+
mock(@existing_session).start
157+
mock(@existing_session).create_channel { @channel }
158+
mock(@channel).exchange('another_exchange', type: :topic, durable: false, :auto_delete => false, arguments: { 'x-arg' => 'value' }) do
159+
@exchange
160+
end
161+
mock(@exchange).publish('test msg 2', my_vars)
162+
p.publish('test msg 2', my_vars)
163+
end
139164
end
140165

141166
it 'should publish using the content type serializer' do

0 commit comments

Comments
 (0)