bunny 2.19.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -32
- data/lib/bunny/channel.rb +86 -10
- data/lib/bunny/consumer.rb +2 -2
- data/lib/bunny/delivery_info.rb +1 -1
- data/lib/bunny/queue.rb +33 -2
- data/lib/bunny/session.rb +1 -1
- data/lib/bunny/transport.rb +30 -1
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +45 -4
- metadata +4 -144
- data/spec/config/enabled_plugins +0 -1
- data/spec/config/rabbitmq.conf +0 -13
- data/spec/higher_level_api/integration/basic_ack_spec.rb +0 -230
- data/spec/higher_level_api/integration/basic_cancel_spec.rb +0 -142
- data/spec/higher_level_api/integration/basic_consume_spec.rb +0 -357
- data/spec/higher_level_api/integration/basic_consume_with_objects_spec.rb +0 -54
- data/spec/higher_level_api/integration/basic_get_spec.rb +0 -80
- data/spec/higher_level_api/integration/basic_nack_spec.rb +0 -82
- data/spec/higher_level_api/integration/basic_publish_spec.rb +0 -74
- data/spec/higher_level_api/integration/basic_qos_spec.rb +0 -57
- data/spec/higher_level_api/integration/basic_reject_spec.rb +0 -152
- data/spec/higher_level_api/integration/basic_return_spec.rb +0 -33
- data/spec/higher_level_api/integration/channel_close_spec.rb +0 -66
- data/spec/higher_level_api/integration/channel_open_spec.rb +0 -57
- data/spec/higher_level_api/integration/connection_recovery_spec.rb +0 -483
- data/spec/higher_level_api/integration/connection_spec.rb +0 -589
- data/spec/higher_level_api/integration/connection_stop_spec.rb +0 -83
- data/spec/higher_level_api/integration/consumer_cancellation_notification_spec.rb +0 -128
- data/spec/higher_level_api/integration/dead_lettering_spec.rb +0 -75
- data/spec/higher_level_api/integration/exchange_bind_spec.rb +0 -31
- data/spec/higher_level_api/integration/exchange_declare_spec.rb +0 -237
- data/spec/higher_level_api/integration/exchange_delete_spec.rb +0 -105
- data/spec/higher_level_api/integration/exchange_unbind_spec.rb +0 -40
- data/spec/higher_level_api/integration/exclusive_queue_spec.rb +0 -28
- data/spec/higher_level_api/integration/heartbeat_spec.rb +0 -49
- data/spec/higher_level_api/integration/message_properties_access_spec.rb +0 -95
- data/spec/higher_level_api/integration/predeclared_exchanges_spec.rb +0 -24
- data/spec/higher_level_api/integration/publisher_confirms_spec.rb +0 -191
- data/spec/higher_level_api/integration/publishing_edge_cases_spec.rb +0 -87
- data/spec/higher_level_api/integration/queue_bind_spec.rb +0 -109
- data/spec/higher_level_api/integration/queue_declare_spec.rb +0 -285
- data/spec/higher_level_api/integration/queue_delete_spec.rb +0 -41
- data/spec/higher_level_api/integration/queue_purge_spec.rb +0 -30
- data/spec/higher_level_api/integration/queue_unbind_spec.rb +0 -54
- data/spec/higher_level_api/integration/read_only_consumer_spec.rb +0 -60
- data/spec/higher_level_api/integration/sender_selected_distribution_spec.rb +0 -36
- data/spec/higher_level_api/integration/tls_connection_spec.rb +0 -255
- data/spec/higher_level_api/integration/toxiproxy_spec.rb +0 -76
- data/spec/higher_level_api/integration/tx_commit_spec.rb +0 -21
- data/spec/higher_level_api/integration/tx_rollback_spec.rb +0 -21
- data/spec/higher_level_api/integration/with_channel_spec.rb +0 -25
- data/spec/issues/issue100_spec.rb +0 -42
- data/spec/issues/issue141_spec.rb +0 -43
- data/spec/issues/issue202_spec.rb +0 -15
- data/spec/issues/issue224_spec.rb +0 -40
- data/spec/issues/issue465_spec.rb +0 -32
- data/spec/issues/issue549_spec.rb +0 -30
- data/spec/issues/issue609_spec.rb +0 -84
- data/spec/issues/issue78_spec.rb +0 -72
- data/spec/issues/issue83_spec.rb +0 -30
- data/spec/issues/issue97_attachment.json +0 -1
- data/spec/issues/issue97_spec.rb +0 -175
- data/spec/lower_level_api/integration/basic_cancel_spec.rb +0 -83
- data/spec/lower_level_api/integration/basic_consume_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -47
- data/spec/stress/channel_close_stress_spec.rb +0 -64
- data/spec/stress/channel_open_stress_spec.rb +0 -84
- data/spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb +0 -28
- data/spec/stress/concurrent_consumers_stress_spec.rb +0 -71
- data/spec/stress/concurrent_publishers_stress_spec.rb +0 -54
- data/spec/stress/connection_open_close_spec.rb +0 -52
- data/spec/stress/merry_go_round_spec.rb +0 -105
- data/spec/toxiproxy_helper.rb +0 -28
- data/spec/unit/bunny_spec.rb +0 -15
- data/spec/unit/concurrent/atomic_fixnum_spec.rb +0 -35
- data/spec/unit/concurrent/condition_spec.rb +0 -82
- data/spec/unit/concurrent/linked_continuation_queue_spec.rb +0 -35
- data/spec/unit/concurrent/synchronized_sorted_set_spec.rb +0 -73
- data/spec/unit/exchange_recovery_spec.rb +0 -39
- data/spec/unit/version_delivery_tag_spec.rb +0 -28
@@ -1,589 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
def local_hostname
|
4
|
-
ENV.fetch("BUNNY_RABBITMQ_HOSTNAME", "127.0.0.1")
|
5
|
-
end
|
6
|
-
|
7
|
-
describe Bunny::Session do
|
8
|
-
let(:port) { AMQ::Protocol::DEFAULT_PORT }
|
9
|
-
let(:username) { "guest" }
|
10
|
-
|
11
|
-
let(:tls_port) { AMQ::Protocol::TLS_PORT }
|
12
|
-
|
13
|
-
context "initialized via connection URI" do
|
14
|
-
after :each do
|
15
|
-
subject.close if subject.open?
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when schema is not one of [amqp, amqps]" do
|
19
|
-
it "raises ArgumentError" do
|
20
|
-
expect {
|
21
|
-
described_class.new("http://127.0.0.1")
|
22
|
-
}.to raise_error(ArgumentError, /amqp or amqps schema/)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "handles amqp:// URIs w/o path part" do
|
27
|
-
session = described_class.new("amqp://127.0.0.1")
|
28
|
-
session.start
|
29
|
-
|
30
|
-
expect(session.vhost).to eq "/"
|
31
|
-
expect(session.host).to eq "127.0.0.1"
|
32
|
-
expect(session.port).to eq 5672
|
33
|
-
expect(session.ssl?).to eq false
|
34
|
-
|
35
|
-
session.close
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when URI ends in a slash" do
|
39
|
-
it "parses vhost as an empty string" do
|
40
|
-
session = described_class.new("amqp://127.0.0.1/")
|
41
|
-
|
42
|
-
expect(session.hostname).to eq "127.0.0.1"
|
43
|
-
expect(session.port).to eq 5672
|
44
|
-
expect(session.vhost).to eq ""
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when URI is amqp://dev.rabbitmq.com/a/path/with/slashes" do
|
49
|
-
it "raises an ArgumentError" do
|
50
|
-
expect { described_class.new("amqp://dev.rabbitmq.com/a/path/with/slashes") }.to raise_error(ArgumentError)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "initialized with all defaults" do
|
56
|
-
it "provides a way to fine tune socket options" do
|
57
|
-
conn = Bunny.new
|
58
|
-
conn.start
|
59
|
-
expect(conn.transport.socket).to respond_to(:setsockopt)
|
60
|
-
|
61
|
-
conn.close
|
62
|
-
end
|
63
|
-
|
64
|
-
it "successfully negotiates the connection" do
|
65
|
-
conn = Bunny.new
|
66
|
-
conn.start
|
67
|
-
expect(conn).to be_connected
|
68
|
-
|
69
|
-
expect(conn.server_properties).not_to be_nil
|
70
|
-
expect(conn.server_capabilities).not_to be_nil
|
71
|
-
|
72
|
-
props = conn.server_properties
|
73
|
-
|
74
|
-
expect(props["product"]).not_to be_nil
|
75
|
-
expect(props["platform"]).not_to be_nil
|
76
|
-
expect(props["version"]).not_to be_nil
|
77
|
-
|
78
|
-
conn.close
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
unless ENV["CI"]
|
83
|
-
context "initialized with TCP connection timeout = 5" do
|
84
|
-
it "successfully connects" do
|
85
|
-
conn = described_class.new(connection_timeout: 5)
|
86
|
-
conn.start
|
87
|
-
expect(conn).to be_connected
|
88
|
-
|
89
|
-
expect(conn.server_properties).not_to be_nil
|
90
|
-
expect(conn.server_capabilities).not_to be_nil
|
91
|
-
|
92
|
-
props = conn.server_properties
|
93
|
-
|
94
|
-
expect(props["product"]).not_to be_nil
|
95
|
-
expect(props["platform"]).not_to be_nil
|
96
|
-
expect(props["version"]).not_to be_nil
|
97
|
-
|
98
|
-
conn.close
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "initialized with hostname: 127.0.0.1" do
|
103
|
-
after :each do
|
104
|
-
subject.close if subject.open?
|
105
|
-
end
|
106
|
-
|
107
|
-
let(:host) { "127.0.0.1" }
|
108
|
-
subject do
|
109
|
-
described_class.new(hostname: host)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "uses hostname = 127.0.0.1" do
|
113
|
-
expect(subject.host).to eq host
|
114
|
-
expect(subject.hostname).to eq host
|
115
|
-
end
|
116
|
-
|
117
|
-
it "uses port 5672" do
|
118
|
-
expect(subject.port).to eq port
|
119
|
-
end
|
120
|
-
|
121
|
-
it "uses username = guest" do
|
122
|
-
expect(subject.username).to eq username
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "initialized with hostname: localhost" do
|
127
|
-
after :each do
|
128
|
-
subject.close if subject.open?
|
129
|
-
end
|
130
|
-
|
131
|
-
let(:host) { "localhost" }
|
132
|
-
let(:subject) { described_class.new(hostname: host) }
|
133
|
-
|
134
|
-
it "uses hostname = localhost" do
|
135
|
-
expect(subject.host).to eq host
|
136
|
-
expect(subject.hostname).to eq host
|
137
|
-
end
|
138
|
-
|
139
|
-
it "uses port 5672" do
|
140
|
-
expect(subject.port).to eq port
|
141
|
-
end
|
142
|
-
|
143
|
-
it "uses username = guest" do
|
144
|
-
expect(subject.username).to eq username
|
145
|
-
expect(subject.user).to eq username
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context "initialized with a list of hosts" do
|
150
|
-
after :each do
|
151
|
-
subject.close if subject.open?
|
152
|
-
end
|
153
|
-
|
154
|
-
let(:host) { "192.168.1.10" }
|
155
|
-
let(:hosts) { [host] }
|
156
|
-
let(:subject) { described_class.new(hosts: hosts) }
|
157
|
-
|
158
|
-
it "uses hostname = 192.168.1.10" do
|
159
|
-
expect(subject.host).to eq host
|
160
|
-
expect(subject.hostname).to eq host
|
161
|
-
end
|
162
|
-
|
163
|
-
it "uses port 5672" do
|
164
|
-
expect(subject.port).to eq port
|
165
|
-
end
|
166
|
-
|
167
|
-
it "uses username = guest" do
|
168
|
-
expect(subject.username).to eq username
|
169
|
-
expect(subject.user).to eq username
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context "initialized with a list of addresses" do
|
174
|
-
after :each do
|
175
|
-
subject.close if subject.open?
|
176
|
-
end
|
177
|
-
|
178
|
-
let(:host) { "192.168.1.10" }
|
179
|
-
let(:port) { 5673 }
|
180
|
-
let(:address) { "#{host}:#{port}" }
|
181
|
-
let(:addresses) { [address] }
|
182
|
-
let(:subject) { described_class.new(addresses: addresses) }
|
183
|
-
|
184
|
-
it "uses hostname = 192.168.1.10" do
|
185
|
-
expect(subject.host).to eq host
|
186
|
-
expect(subject.hostname).to eq host
|
187
|
-
end
|
188
|
-
|
189
|
-
it "uses port 5673" do
|
190
|
-
expect(subject.port).to eq port
|
191
|
-
end
|
192
|
-
|
193
|
-
it "uses username = guest" do
|
194
|
-
expect(subject.username).to eq username
|
195
|
-
expect(subject.user).to eq username
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
context "initialized with addresses: [...] with quoted IPv6 hostnames" do
|
200
|
-
after :each do
|
201
|
-
subject.close if subject.open?
|
202
|
-
end
|
203
|
-
|
204
|
-
let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
|
205
|
-
let(:port) { 5673 }
|
206
|
-
let(:address) { "#{host}:#{port}" }
|
207
|
-
let(:addresses) { [address] }
|
208
|
-
let(:subject) { described_class.new(addresses: addresses) }
|
209
|
-
|
210
|
-
it "uses correct hostname" do
|
211
|
-
expect(subject.host).to eq host
|
212
|
-
expect(subject.hostname).to eq host
|
213
|
-
end
|
214
|
-
|
215
|
-
it "uses port 5673" do
|
216
|
-
expect(subject.port).to eq port
|
217
|
-
end
|
218
|
-
|
219
|
-
it "uses username = guest" do
|
220
|
-
expect(subject.username).to eq username
|
221
|
-
expect(subject.user).to eq username
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context "initialized with addresses: [...] with quoted IPv6 hostnames without ports" do
|
226
|
-
after :each do
|
227
|
-
subject.close if subject.open?
|
228
|
-
end
|
229
|
-
|
230
|
-
let(:host) { "[2001:db8:85a3:8d3:1319:8a2e:370:7348]" }
|
231
|
-
let(:address) { host }
|
232
|
-
let(:addresses) { [address] }
|
233
|
-
let(:subject) { described_class.new(addresses: addresses) }
|
234
|
-
|
235
|
-
it "uses correct hostname" do
|
236
|
-
expect(subject.host).to eq host
|
237
|
-
expect(subject.hostname).to eq host
|
238
|
-
end
|
239
|
-
|
240
|
-
it "uses port 5672" do
|
241
|
-
expect(subject.port).to eq 5672
|
242
|
-
end
|
243
|
-
|
244
|
-
it "uses username = guest" do
|
245
|
-
expect(subject.username).to eq username
|
246
|
-
expect(subject.user).to eq username
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context "initialized with addresses: [...] with an quoted IPv6 hostnames" do
|
251
|
-
after :each do
|
252
|
-
subject.close if subject.open?
|
253
|
-
end
|
254
|
-
|
255
|
-
let(:host) { "2001:db8:85a3:8d3:1319:8a2e:370:7348" }
|
256
|
-
let(:port) { 5673 }
|
257
|
-
let(:address) { "#{host}:#{port}" }
|
258
|
-
let(:addresses) { [address] }
|
259
|
-
let(:subject) { described_class.new(addresses: addresses) }
|
260
|
-
|
261
|
-
it "fails to correctly parse the host (and emits a warning)" do
|
262
|
-
expect(subject.host).to eq "2001"
|
263
|
-
expect(subject.hostname).to eq "2001"
|
264
|
-
end
|
265
|
-
|
266
|
-
it "fails to correctly parse the port (and emits a warning)" do
|
267
|
-
expect(subject.port).to eq 0
|
268
|
-
end
|
269
|
-
|
270
|
-
it "uses username = guest" do
|
271
|
-
expect(subject.username).to eq username
|
272
|
-
expect(subject.user).to eq username
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
context "initialized with conflicting hosts and addresses" do
|
277
|
-
let(:host) { "192.168.1.10" }
|
278
|
-
let(:port) { 5673 }
|
279
|
-
let(:address) { "#{host}:#{port}" }
|
280
|
-
let(:io) { StringIO.new }
|
281
|
-
let(:logger) { ::Logger.new(io) }
|
282
|
-
|
283
|
-
it "raises an argument error when there is are hosts and an address" do
|
284
|
-
expect { described_class.new(addresses: [address], hosts: [host]) }.to raise_error(ArgumentError)
|
285
|
-
end
|
286
|
-
|
287
|
-
it "logs a warning when there is a single host and an array" do
|
288
|
-
described_class.new(addresses: [address], host: host, logger: logger)
|
289
|
-
expect(io.string).to match(/both a host and an array of hosts/)
|
290
|
-
end
|
291
|
-
|
292
|
-
it "converts hosts in addresses to addresses" do
|
293
|
-
strategy = Proc.new { |addresses| addresses }
|
294
|
-
session = described_class.new(addresses: [address,host ], hosts_shuffle_strategy: strategy)
|
295
|
-
strategy = Proc.new { |addresses| addresses }
|
296
|
-
|
297
|
-
expect(session.to_s).to include 'addresses=[192.168.1.10:5673,192.168.1.10:5672]'
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
context "initialized with channel_max: 4096" do
|
302
|
-
after :each do
|
303
|
-
subject.close if subject.open?
|
304
|
-
end
|
305
|
-
|
306
|
-
let(:channel_max) { 1024 }
|
307
|
-
let(:subject) { described_class.new(channel_max: channel_max) }
|
308
|
-
|
309
|
-
# this assumes RabbitMQ has no lower value configured. In 3.2
|
310
|
-
# it is 0 (no limit) by default and 1024 is still a fairly low value
|
311
|
-
# for future releases. MK.
|
312
|
-
it "negotiates channel max to be 1024" do
|
313
|
-
subject.start
|
314
|
-
expect(subject.channel_max).to eq channel_max
|
315
|
-
|
316
|
-
subject.close
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
context "initialized with ssl: true" do
|
321
|
-
let(:subject) do
|
322
|
-
described_class.new(username: "bunny_gem",
|
323
|
-
password: "bunny_password",
|
324
|
-
vhost: "bunny_testbed",
|
325
|
-
ssl: true,
|
326
|
-
ssl_cert: "spec/tls/client_certificate.pem",
|
327
|
-
ssl_key: "spec/tls/client_key.pem",
|
328
|
-
ssl_ca_certificates: ["./spec/tls/ca_certificate.pem"])
|
329
|
-
end
|
330
|
-
|
331
|
-
it "uses TLS port" do
|
332
|
-
expect(subject.port).to eq tls_port
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
context "initialized with tls: true" do
|
337
|
-
let(:subject) do
|
338
|
-
described_class.new(username: "bunny_gem",
|
339
|
-
password: "bunny_password",
|
340
|
-
vhost: "bunny_testbed",
|
341
|
-
tls: true,
|
342
|
-
tls_cert: "spec/tls/client_certificate.pem",
|
343
|
-
tls_key: "spec/tls/client_key.pem",
|
344
|
-
tls_ca_certificates: ["./spec/tls/ca_certificate.pem"])
|
345
|
-
end
|
346
|
-
|
347
|
-
it "uses TLS port" do
|
348
|
-
expect(subject.port).to eq tls_port
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
context "initialized with hostname: 127.0.0.1 and non-default credentials" do
|
354
|
-
after :each do
|
355
|
-
subject.close if subject.open?
|
356
|
-
end
|
357
|
-
|
358
|
-
let(:host) { "127.0.0.1" }
|
359
|
-
# see ./bin/ci/before_build
|
360
|
-
let(:username) { "bunny_gem" }
|
361
|
-
let(:password) { "bunny_password" }
|
362
|
-
let(:vhost) { "bunny_testbed" }
|
363
|
-
|
364
|
-
subject do
|
365
|
-
described_class.new(hostname: host, username: username, password: password, virtual_host: vhost)
|
366
|
-
end
|
367
|
-
|
368
|
-
it "successfully connects" do
|
369
|
-
5.times { subject.start }
|
370
|
-
expect(subject).to be_connected
|
371
|
-
|
372
|
-
expect(subject.server_properties).not_to be_nil
|
373
|
-
expect(subject.server_capabilities).not_to be_nil
|
374
|
-
|
375
|
-
props = subject.server_properties
|
376
|
-
|
377
|
-
expect(props["product"]).not_to be_nil
|
378
|
-
expect(props["platform"]).not_to be_nil
|
379
|
-
expect(props["version"]).not_to be_nil
|
380
|
-
end
|
381
|
-
|
382
|
-
it "uses hostname = 127.0.0.1" do
|
383
|
-
expect(subject.host).to eq host
|
384
|
-
expect(subject.hostname).to eq host
|
385
|
-
end
|
386
|
-
|
387
|
-
it "uses port 5672" do
|
388
|
-
expect(subject.port).to eq port
|
389
|
-
end
|
390
|
-
|
391
|
-
it "uses provided vhost" do
|
392
|
-
expect(subject.vhost).to eq vhost
|
393
|
-
expect(subject.virtual_host).to eq vhost
|
394
|
-
end
|
395
|
-
|
396
|
-
it "uses provided username" do
|
397
|
-
expect(subject.username).to eq username
|
398
|
-
end
|
399
|
-
|
400
|
-
it "uses provided password" do
|
401
|
-
expect(subject.password).to eq password
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
context "initialized with hostname: 127.0.0.1 and non-default credentials (take 2)" do
|
406
|
-
after :each do
|
407
|
-
subject.close if subject.open?
|
408
|
-
end
|
409
|
-
|
410
|
-
let(:host) { "127.0.0.1" }
|
411
|
-
# see ./bin/ci/before_build
|
412
|
-
let(:username) { "bunny_gem" }
|
413
|
-
let(:password) { "bunny_password" }
|
414
|
-
let(:vhost) { "bunny_testbed" }
|
415
|
-
|
416
|
-
subject do
|
417
|
-
described_class.new(hostname: host, username: username, password: password, vhost: vhost)
|
418
|
-
end
|
419
|
-
|
420
|
-
it "successfully connects" do
|
421
|
-
subject.start
|
422
|
-
expect(subject).to be_connected
|
423
|
-
|
424
|
-
expect(subject.server_properties).not_to be_nil
|
425
|
-
expect(subject.server_capabilities).not_to be_nil
|
426
|
-
|
427
|
-
props = subject.server_properties
|
428
|
-
|
429
|
-
expect(props["product"]).not_to be_nil
|
430
|
-
expect(props["platform"]).not_to be_nil
|
431
|
-
expect(props["version"]).not_to be_nil
|
432
|
-
end
|
433
|
-
|
434
|
-
it "uses hostname = 127.0.0.1" do
|
435
|
-
expect(subject.host).to eq host
|
436
|
-
expect(subject.hostname).to eq host
|
437
|
-
end
|
438
|
-
|
439
|
-
it "uses port 5672" do
|
440
|
-
expect(subject.port).to eq port
|
441
|
-
end
|
442
|
-
|
443
|
-
it "uses provided username" do
|
444
|
-
expect(subject.username).to eq username
|
445
|
-
end
|
446
|
-
|
447
|
-
it "uses provided password" do
|
448
|
-
expect(subject.password).to eq password
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
context "initialized with hostname: 127.0.0.1 and non-default credentials (take 2)" do
|
453
|
-
after :each do
|
454
|
-
subject.close if subject.open?
|
455
|
-
end
|
456
|
-
|
457
|
-
let(:host) { "127.0.0.1" }
|
458
|
-
# see ./bin/ci/before_build
|
459
|
-
let(:username) { "bunny_gem" }
|
460
|
-
let(:password) { "bunny_password" }
|
461
|
-
let(:vhost) { "bunny_testbed" }
|
462
|
-
let(:interval) { 1 }
|
463
|
-
|
464
|
-
subject do
|
465
|
-
described_class.new(hostname: host, username: username, password: password, vhost: vhost, heartbeat_timeout: interval)
|
466
|
-
end
|
467
|
-
|
468
|
-
it "successfully connects" do
|
469
|
-
subject.start
|
470
|
-
expect(subject).to be_connected
|
471
|
-
|
472
|
-
expect(subject.server_properties).not_to be_nil
|
473
|
-
expect(subject.server_capabilities).not_to be_nil
|
474
|
-
|
475
|
-
props = subject.server_properties
|
476
|
-
|
477
|
-
expect(props["product"]).not_to be_nil
|
478
|
-
expect(props["platform"]).not_to be_nil
|
479
|
-
expect(props["version"]).not_to be_nil
|
480
|
-
expect(props["capabilities"]).not_to be_nil
|
481
|
-
|
482
|
-
# this is negotiated with RabbitMQ, so we need to
|
483
|
-
# establish the connection first
|
484
|
-
expect(subject.heartbeat).to eq interval
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
context "initialized with hostname: 127.0.0.1 and INVALID credentials" do
|
489
|
-
let(:host) { "127.0.0.1" }
|
490
|
-
# see ./bin/ci/before_build
|
491
|
-
let(:username) { "bunny_gem#{Time.now.to_i}" }
|
492
|
-
let(:password) { "sdjkfhsdf8ysd8fy8" }
|
493
|
-
let(:vhost) { "___sd89aysd98789" }
|
494
|
-
|
495
|
-
subject do
|
496
|
-
described_class.new(hostname: host, username: username, password: password, vhost: vhost)
|
497
|
-
end
|
498
|
-
|
499
|
-
it "fails to connect" do
|
500
|
-
expect do
|
501
|
-
subject.start
|
502
|
-
end.to raise_error(Bunny::PossibleAuthenticationFailureError)
|
503
|
-
end
|
504
|
-
|
505
|
-
it "uses provided username" do
|
506
|
-
expect(subject.username).to eq username
|
507
|
-
end
|
508
|
-
|
509
|
-
it "uses provided password" do
|
510
|
-
expect(subject.password).to eq password
|
511
|
-
end
|
512
|
-
end
|
513
|
-
|
514
|
-
context "initialized with unreachable host or port" do
|
515
|
-
it "fails to connect" do
|
516
|
-
expect do
|
517
|
-
c = described_class.new(port: 38000)
|
518
|
-
c.start
|
519
|
-
end.to raise_error(Bunny::TCPConnectionFailed)
|
520
|
-
end
|
521
|
-
|
522
|
-
it "is not connected" do
|
523
|
-
begin
|
524
|
-
c = described_class.new(port: 38000)
|
525
|
-
c.start
|
526
|
-
rescue Bunny::TCPConnectionFailed => e
|
527
|
-
true
|
528
|
-
end
|
529
|
-
|
530
|
-
expect(subject.status).to eq :not_connected
|
531
|
-
end
|
532
|
-
|
533
|
-
it "is not open" do
|
534
|
-
begin
|
535
|
-
c = described_class.new(port: 38000)
|
536
|
-
c.start
|
537
|
-
rescue Bunny::TCPConnectionFailed => e
|
538
|
-
true
|
539
|
-
end
|
540
|
-
|
541
|
-
expect(subject).not_to be_open
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
context "initialized with a custom logger object" do
|
546
|
-
let(:io) { StringIO.new }
|
547
|
-
let(:logger) { ::Logger.new(io) }
|
548
|
-
|
549
|
-
it "uses provided logger" do
|
550
|
-
conn = described_class.new(logger: logger)
|
551
|
-
conn.start
|
552
|
-
|
553
|
-
expect(io.string.length).to be > 100
|
554
|
-
|
555
|
-
conn.close
|
556
|
-
end
|
557
|
-
|
558
|
-
it "doesn't reassign the logger's progname attribute" do
|
559
|
-
expect(logger).not_to receive(:progname=)
|
560
|
-
described_class.new(logger: logger)
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
context "initialized with a custom connection name" do
|
565
|
-
it "uses provided connection name with default connection string" do
|
566
|
-
conn = Bunny.new(connection_name: 'test_name')
|
567
|
-
|
568
|
-
expect(conn.connection_name).to eq 'test_name'
|
569
|
-
end
|
570
|
-
|
571
|
-
it "uses provided connection name from client property hash" do
|
572
|
-
conn = Bunny.new(client_properties: {connection_name: 'cp/test_name'})
|
573
|
-
|
574
|
-
expect(conn.connection_name).to eq 'cp/test_name'
|
575
|
-
end
|
576
|
-
|
577
|
-
it "uses provided connection name with custom connection string" do
|
578
|
-
conn = Bunny.new('amqp://guest:guest@rabbitmq:5672', connection_name: 'test_name3')
|
579
|
-
|
580
|
-
expect(conn.connection_name).to eq 'test_name3'
|
581
|
-
end
|
582
|
-
|
583
|
-
it "uses provided connection name with hash options" do
|
584
|
-
conn = Bunny.new(user: 'user', password: 'p455w0rd', connection_name: 'test_name4')
|
585
|
-
|
586
|
-
expect(conn.connection_name).to eq 'test_name4'
|
587
|
-
end
|
588
|
-
end
|
589
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Session do
|
4
|
-
let(:http_client) { RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }
|
5
|
-
|
6
|
-
def close_connection(client_port)
|
7
|
-
# let whatever actions were taken before
|
8
|
-
# this call a chance to propagate, e.g. to make
|
9
|
-
# sure that connections are accounted for in the
|
10
|
-
# stats DB.
|
11
|
-
#
|
12
|
-
# See bin/ci/before_build for management plugin
|
13
|
-
# pre-configuration.
|
14
|
-
#
|
15
|
-
# MK.
|
16
|
-
sleep 1.1
|
17
|
-
c = http_client.
|
18
|
-
list_connections.
|
19
|
-
find { |conn_info| conn_info && conn_info.peer_port.to_i == client_port }
|
20
|
-
|
21
|
-
http_client.close_connection(c.name) if c
|
22
|
-
end
|
23
|
-
|
24
|
-
def wait_for_recovery
|
25
|
-
sleep 1.5
|
26
|
-
end
|
27
|
-
|
28
|
-
it "can be closed" do
|
29
|
-
c = Bunny.new(automatically_recover: false)
|
30
|
-
c.start
|
31
|
-
ch = c.create_channel
|
32
|
-
|
33
|
-
expect(c).to be_connected
|
34
|
-
c.stop
|
35
|
-
expect(c).to be_closed
|
36
|
-
end
|
37
|
-
|
38
|
-
it "can be closed twice (Session#close is idempotent)" do
|
39
|
-
c = Bunny.new(automatically_recover: false)
|
40
|
-
c.start
|
41
|
-
ch = c.create_channel
|
42
|
-
|
43
|
-
expect(c).to be_connected
|
44
|
-
c.stop
|
45
|
-
expect(c).to be_closed
|
46
|
-
c.stop
|
47
|
-
expect(c).to be_closed
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "in a single threaded mode" do
|
51
|
-
it "can be closed" do
|
52
|
-
c = Bunny.new(automatically_recover: false, threaded: false)
|
53
|
-
c.start
|
54
|
-
ch = c.create_channel
|
55
|
-
|
56
|
-
expect(c).to be_connected
|
57
|
-
c.stop
|
58
|
-
expect(c).to be_closed
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
describe "that recovers from connection.close" do
|
64
|
-
it "can be closed" do
|
65
|
-
c = Bunny.new(automatically_recover: true,
|
66
|
-
recover_from_connection_close: true,
|
67
|
-
network_recovery_interval: 0.2)
|
68
|
-
c.start
|
69
|
-
ch = c.create_channel
|
70
|
-
|
71
|
-
sleep 1.5
|
72
|
-
expect(c).to be_open
|
73
|
-
sleep 1.5
|
74
|
-
close_connection(c.local_port)
|
75
|
-
|
76
|
-
wait_for_recovery
|
77
|
-
expect(c).to be_open
|
78
|
-
expect(ch).to be_open
|
79
|
-
|
80
|
-
c.close
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|