bunny 2.15.0 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -39
- data/lib/bunny/channel.rb +89 -13
- data/lib/bunny/consumer.rb +2 -2
- data/lib/bunny/consumer_work_pool.rb +1 -1
- data/lib/bunny/delivery_info.rb +1 -1
- data/lib/bunny/queue.rb +36 -2
- data/lib/bunny/reader_loop.rb +11 -11
- data/lib/bunny/session.rb +71 -25
- data/lib/bunny/transport.rb +49 -12
- data/lib/bunny/version.rb +1 -1
- data/lib/bunny.rb +45 -4
- metadata +29 -228
- data/.github/ISSUE_TEMPLATE.md +0 -18
- data/.gitignore +0 -28
- data/.rspec +0 -1
- data/.travis.yml +0 -33
- data/.yardopts +0 -8
- data/CONTRIBUTING.md +0 -132
- data/ChangeLog.md +0 -2084
- data/Gemfile +0 -55
- data/LICENSE +0 -21
- data/Rakefile +0 -54
- data/benchmarks/basic_publish/with_128K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_1k_messages.rb +0 -35
- data/benchmarks/basic_publish/with_4K_messages.rb +0 -35
- data/benchmarks/basic_publish/with_64K_messages.rb +0 -35
- data/benchmarks/channel_open.rb +0 -28
- data/benchmarks/mutex_and_monitor.rb +0 -42
- data/benchmarks/queue_declare.rb +0 -29
- data/benchmarks/queue_declare_and_bind.rb +0 -29
- data/benchmarks/queue_declare_bind_and_delete.rb +0 -29
- data/benchmarks/synchronized_sorted_set.rb +0 -53
- data/benchmarks/write_vs_write_nonblock.rb +0 -49
- data/bunny.gemspec +0 -34
- data/docker/Dockerfile +0 -24
- data/docker/apt/preferences.d/erlang +0 -3
- data/docker/apt/sources.list.d/bintray.rabbitmq.list +0 -2
- data/docker/docker-entrypoint.sh +0 -26
- data/docker/rabbitmq.conf +0 -29
- data/docker-compose.yml +0 -28
- data/examples/connection/authentication_failure.rb +0 -16
- data/examples/connection/automatic_recovery_with_basic_get.rb +0 -40
- data/examples/connection/automatic_recovery_with_client_named_queues.rb +0 -36
- data/examples/connection/automatic_recovery_with_multiple_consumers.rb +0 -46
- data/examples/connection/automatic_recovery_with_republishing.rb +0 -109
- data/examples/connection/automatic_recovery_with_server_named_queues.rb +0 -35
- data/examples/connection/channel_level_exception.rb +0 -27
- data/examples/connection/disabled_automatic_recovery.rb +0 -34
- data/examples/connection/heartbeat.rb +0 -17
- data/examples/connection/manually_reconnecting_consumer.rb +0 -23
- data/examples/connection/manually_reconnecting_publisher.rb +0 -28
- data/examples/connection/unknown_host.rb +0 -16
- data/examples/consumers/high_and_low_priority.rb +0 -50
- data/examples/guides/exchanges/direct_exchange_routing.rb +0 -36
- data/examples/guides/exchanges/fanout_exchange_routing.rb +0 -28
- data/examples/guides/exchanges/headers_exchange_routing.rb +0 -31
- data/examples/guides/exchanges/mandatory_messages.rb +0 -30
- data/examples/guides/extensions/alternate_exchange.rb +0 -30
- data/examples/guides/extensions/basic_nack.rb +0 -33
- data/examples/guides/extensions/connection_blocked.rb +0 -35
- data/examples/guides/extensions/consumer_cancellation_notification.rb +0 -39
- data/examples/guides/extensions/dead_letter_exchange.rb +0 -32
- data/examples/guides/extensions/exchange_to_exchange_bindings.rb +0 -29
- data/examples/guides/extensions/per_message_ttl.rb +0 -36
- data/examples/guides/extensions/per_queue_message_ttl.rb +0 -36
- data/examples/guides/extensions/publisher_confirms.rb +0 -28
- data/examples/guides/extensions/queue_lease.rb +0 -26
- data/examples/guides/extensions/sender_selected_distribution.rb +0 -32
- data/examples/guides/getting_started/blabbr.rb +0 -27
- data/examples/guides/getting_started/hello_world.rb +0 -22
- data/examples/guides/getting_started/weathr.rb +0 -49
- data/examples/guides/queues/one_off_consumer.rb +0 -25
- data/examples/guides/queues/redeliveries.rb +0 -81
- data/profiling/basic_publish/with_4K_messages.rb +0 -33
- data/repl +0 -3
- 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 -349
- 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 -563
- 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 -262
- 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/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/tls/ca_certificate.pem +0 -29
- data/spec/tls/ca_key.pem +0 -52
- data/spec/tls/client_certificate.pem +0 -29
- data/spec/tls/client_key.pem +0 -51
- data/spec/tls/generate-server-cert.sh +0 -8
- data/spec/tls/server-openssl.cnf +0 -10
- data/spec/tls/server.csr +0 -16
- data/spec/tls/server_certificate.pem +0 -29
- data/spec/tls/server_key.pem +0 -51
- 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,262 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
require "socket"
|
5
|
-
|
6
|
-
CERTIFICATE_DIR = ENV.fetch("BUNNY_CERTIFICATE_DIR", "./spec/tls")
|
7
|
-
puts "Will use certificates from #{CERTIFICATE_DIR}"
|
8
|
-
|
9
|
-
shared_examples_for "successful TLS connection" do
|
10
|
-
it "succeeds", skip: ENV["CI"] do
|
11
|
-
expect(subject).to be_tls
|
12
|
-
ch = subject.create_channel
|
13
|
-
ch.confirm_select
|
14
|
-
|
15
|
-
q = ch.queue("", exclusive: true)
|
16
|
-
x = ch.default_exchange
|
17
|
-
|
18
|
-
x.publish("xyzzy", routing_key: q.name).
|
19
|
-
publish("xyzzy", routing_key: q.name).
|
20
|
-
publish("xyzzy", routing_key: q.name).
|
21
|
-
publish("xyzzy", routing_key: q.name)
|
22
|
-
|
23
|
-
x.wait_for_confirms
|
24
|
-
expect(q.message_count).to eq 4
|
25
|
-
|
26
|
-
i = 0
|
27
|
-
q.subscribe do |delivery_info, _, payload|
|
28
|
-
i += 1
|
29
|
-
end
|
30
|
-
sleep 1.0
|
31
|
-
expect(i).to eq 4
|
32
|
-
expect(q.message_count).to eq 0
|
33
|
-
|
34
|
-
ch.close
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def local_hostname
|
39
|
-
ENV.fetch("BUNNY_RABBITMQ_HOSTNAME", "localhost")
|
40
|
-
end
|
41
|
-
|
42
|
-
def no_tls12_supported?
|
43
|
-
not tls12_supported?
|
44
|
-
end
|
45
|
-
|
46
|
-
def tls12_supported?
|
47
|
-
begin
|
48
|
-
ctx = OpenSSL::SSL::SSLContext.new
|
49
|
-
ctx.min_version = ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
|
50
|
-
true
|
51
|
-
rescue
|
52
|
-
false
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "initialized with tls: true", skip: ENV["CI"] do
|
57
|
-
let(:subject) do
|
58
|
-
Bunny.new(
|
59
|
-
hostname: local_hostname(),
|
60
|
-
user: "bunny_gem",
|
61
|
-
password: "bunny_password",
|
62
|
-
vhost: "bunny_testbed",
|
63
|
-
tls: true,
|
64
|
-
verify_peer: verify_peer,
|
65
|
-
tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
|
66
|
-
tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
|
67
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"])
|
68
|
-
end
|
69
|
-
|
70
|
-
context "peer verification is off" do
|
71
|
-
let(:verify_peer) { false }
|
72
|
-
|
73
|
-
it "uses TLS port" do
|
74
|
-
expect(subject.port).to eq AMQ::Protocol::TLS_PORT
|
75
|
-
end
|
76
|
-
|
77
|
-
it "sends the SNI details" do
|
78
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
79
|
-
subject.start
|
80
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
81
|
-
end
|
82
|
-
|
83
|
-
after :each do
|
84
|
-
subject.close
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "peer verification is on" do
|
89
|
-
let(:verify_peer) { true }
|
90
|
-
|
91
|
-
it "uses TLS port" do
|
92
|
-
expect(subject.port).to eq AMQ::Protocol::TLS_PORT
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "TLS connection to RabbitMQ with client certificates", skip: ENV["CI"] do
|
98
|
-
let(:subject) do
|
99
|
-
c = Bunny.new(
|
100
|
-
hostname: local_hostname(),
|
101
|
-
username: "bunny_gem",
|
102
|
-
password: "bunny_password",
|
103
|
-
vhost: "bunny_testbed",
|
104
|
-
tls: true,
|
105
|
-
tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
|
106
|
-
tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
|
107
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
108
|
-
verify_peer: false)
|
109
|
-
c.start
|
110
|
-
c
|
111
|
-
end
|
112
|
-
|
113
|
-
after :each do
|
114
|
-
subject.close
|
115
|
-
end
|
116
|
-
|
117
|
-
include_examples "successful TLS connection"
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
describe "TLS connection to RabbitMQ without client certificates", skip: ENV["CI"] do
|
122
|
-
let(:subject) do
|
123
|
-
c = Bunny.new(
|
124
|
-
hostname: local_hostname(),
|
125
|
-
username: "bunny_gem",
|
126
|
-
password: "bunny_password",
|
127
|
-
vhost: "bunny_testbed",
|
128
|
-
tls: true,
|
129
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
130
|
-
verify_peer: false)
|
131
|
-
c.start
|
132
|
-
c
|
133
|
-
end
|
134
|
-
|
135
|
-
after :each do
|
136
|
-
subject.close
|
137
|
-
end
|
138
|
-
|
139
|
-
include_examples "successful TLS connection"
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
describe "TLS connection to RabbitMQ with a connection string", skip: ENV["CI"] do
|
144
|
-
let(:subject) do
|
145
|
-
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
|
146
|
-
tls_cert: "#{CERTIFICATE_DIR}/client_certificate.pem",
|
147
|
-
tls_key: "#{CERTIFICATE_DIR}/client_key.pem",
|
148
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
149
|
-
verify_peer: false)
|
150
|
-
c.start
|
151
|
-
c
|
152
|
-
end
|
153
|
-
|
154
|
-
after :each do
|
155
|
-
subject.close
|
156
|
-
end
|
157
|
-
|
158
|
-
include_examples "successful TLS connection"
|
159
|
-
|
160
|
-
context "when URI contains query parameters" do
|
161
|
-
subject(:session) do
|
162
|
-
Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed?heartbeat=10&connection_timeout=100&channel_max=1000&verify=false&cacertfile=#{CERTIFICATE_DIR}/ca_certificate.pem&certfile=#{CERTIFICATE_DIR}/client_certificate.pem&keyfile=#{CERTIFICATE_DIR}/client_key.pem")
|
163
|
-
end
|
164
|
-
|
165
|
-
it "parses extra connection parameters" do
|
166
|
-
session.start
|
167
|
-
|
168
|
-
expect(session.uses_tls?).to eq(true)
|
169
|
-
expect(session.transport.verify_peer).to eq(false)
|
170
|
-
expect(session.transport.tls_ca_certificates).to eq(["#{CERTIFICATE_DIR}/ca_certificate.pem"])
|
171
|
-
expect(session.transport.tls_certificate_path).to eq("#{CERTIFICATE_DIR}/client_certificate.pem")
|
172
|
-
expect(session.transport.tls_key_path).to eq("#{CERTIFICATE_DIR}/client_key.pem")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
|
-
describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key", skip: ENV["CI"] do
|
179
|
-
let(:subject) do
|
180
|
-
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
|
181
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
182
|
-
verify_peer: verify_peer)
|
183
|
-
c.start
|
184
|
-
c
|
185
|
-
end
|
186
|
-
|
187
|
-
after :each do
|
188
|
-
subject.close
|
189
|
-
end
|
190
|
-
|
191
|
-
context "peer verification is off" do
|
192
|
-
let(:verify_peer) { false }
|
193
|
-
|
194
|
-
include_examples "successful TLS connection"
|
195
|
-
|
196
|
-
it "sends the SNI details" do
|
197
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
198
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "peer verification is on" do
|
203
|
-
let(:verify_peer) { true }
|
204
|
-
|
205
|
-
include_examples "successful TLS connection"
|
206
|
-
|
207
|
-
it "sends the SNI details" do
|
208
|
-
# https://github.com/ruby-amqp/bunny/issues/440
|
209
|
-
expect(subject.transport.socket.hostname).to_not be_empty
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
describe "TLS connection to RabbitMQ with client certificates provided inline", skip: ENV["CI"] do
|
216
|
-
let(:subject) do
|
217
|
-
c = Bunny.new(
|
218
|
-
hostname: local_hostname(),
|
219
|
-
username: "bunny_gem",
|
220
|
-
password: "bunny_password",
|
221
|
-
vhost: "bunny_testbed",
|
222
|
-
tls: true,
|
223
|
-
tls_cert: File.read("#{CERTIFICATE_DIR}/client_certificate.pem"),
|
224
|
-
tls_key: File.read("#{CERTIFICATE_DIR}/client_key.pem"),
|
225
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
226
|
-
verify_peer: false)
|
227
|
-
c.start
|
228
|
-
c
|
229
|
-
end
|
230
|
-
|
231
|
-
after :each do
|
232
|
-
subject.close
|
233
|
-
end
|
234
|
-
|
235
|
-
include_examples "successful TLS connection"
|
236
|
-
end
|
237
|
-
|
238
|
-
describe "TLS connection to RabbitMQ with tls_version TLSv1.2 specified", skip: ENV["CI"] do
|
239
|
-
let(:subject) do
|
240
|
-
c = Bunny.new(
|
241
|
-
hostname: local_hostname(),
|
242
|
-
username: "bunny_gem",
|
243
|
-
password: "bunny_password",
|
244
|
-
vhost: "bunny_testbed",
|
245
|
-
tls: true,
|
246
|
-
tls_protocol: :TLSv1_2,
|
247
|
-
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
|
248
|
-
verify_peer: false)
|
249
|
-
c.start
|
250
|
-
c
|
251
|
-
end
|
252
|
-
|
253
|
-
after :each do
|
254
|
-
subject.close
|
255
|
-
end
|
256
|
-
|
257
|
-
include_examples "successful TLS connection"
|
258
|
-
|
259
|
-
it "connects using TLSv1.2", skip: no_tls12_supported? do
|
260
|
-
expect(subject.transport.socket.ssl_version).to eq "TLSv1.2"
|
261
|
-
end
|
262
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require_relative "../../toxiproxy_helper"
|
3
|
-
|
4
|
-
if ::Toxiproxy.running?
|
5
|
-
describe Bunny::Channel, "#basic_publish" do
|
6
|
-
include RabbitMQ::Toxiproxy
|
7
|
-
|
8
|
-
after :each do
|
9
|
-
@connection.close if @connection.open?
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when the the connection detects missed heartbeats with automatic recovery" do
|
13
|
-
before(:each) do
|
14
|
-
setup_toxiproxy
|
15
|
-
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
16
|
-
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true)
|
17
|
-
@connection.start
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:queue_name) { "bunny.basic.publish.queue#{rand}" }
|
21
|
-
|
22
|
-
it "raises a ConnectionClosedError" do
|
23
|
-
ch = @connection.create_channel
|
24
|
-
begin
|
25
|
-
rabbitmq_toxiproxy.down do
|
26
|
-
sleep 2
|
27
|
-
expect { ch.default_exchange.publish("", :routing_key => queue_name) }.to raise_error(Bunny::ConnectionClosedError)
|
28
|
-
end
|
29
|
-
ensure
|
30
|
-
cleanup_toxiproxy
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when the the connection detects missed heartbeats without automatic recovery" do
|
36
|
-
before(:each) do
|
37
|
-
setup_toxiproxy
|
38
|
-
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
39
|
-
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: false, threaded: false)
|
40
|
-
@connection.start
|
41
|
-
end
|
42
|
-
|
43
|
-
it "does not raise an exception on session thread" do
|
44
|
-
rabbitmq_toxiproxy.down do
|
45
|
-
sleep 5
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "recovery attempt limit that's exceeded" do
|
51
|
-
before(:each) do
|
52
|
-
setup_toxiproxy
|
53
|
-
@connection = Bunny.new(user: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed",
|
54
|
-
host: "localhost:11111", heartbeat_timeout: 1, automatically_recover: true, network_recovery_interval: 1,
|
55
|
-
recovery_attempts: 2, reset_recovery_attempts_after_reconnection: true,
|
56
|
-
disconnect_timeout: 1)
|
57
|
-
@connection.start
|
58
|
-
end
|
59
|
-
|
60
|
-
it "permanently closes connection" do
|
61
|
-
expect(@connection.open?).to be(true)
|
62
|
-
|
63
|
-
rabbitmq_toxiproxy.down do
|
64
|
-
sleep 5
|
65
|
-
end
|
66
|
-
# give the connection one last chance to recover
|
67
|
-
sleep 3
|
68
|
-
|
69
|
-
expect(@connection.open?).to be(false)
|
70
|
-
expect(@connection.closed?).to be(true)
|
71
|
-
end
|
72
|
-
end # context
|
73
|
-
end # describe
|
74
|
-
else
|
75
|
-
puts "Toxiproxy isn't running, some examples will be skipped"
|
76
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#tx_commit" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is supported" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
ch.tx_select
|
17
|
-
ch.tx_commit
|
18
|
-
|
19
|
-
ch.close
|
20
|
-
end
|
21
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#tx_rollback" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is supported" do
|
15
|
-
ch = connection.create_channel
|
16
|
-
ch.tx_select
|
17
|
-
ch.tx_rollback
|
18
|
-
|
19
|
-
ch.close
|
20
|
-
end
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Channel, "#with_channel" do
|
4
|
-
let(:connection) do
|
5
|
-
c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
|
6
|
-
c.start
|
7
|
-
c
|
8
|
-
end
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
connection.close if connection.open?
|
12
|
-
end
|
13
|
-
|
14
|
-
it "closes if the block throws an exception" do
|
15
|
-
ch = nil
|
16
|
-
begin
|
17
|
-
connection.with_channel do |wch|
|
18
|
-
ch = wch
|
19
|
-
raise Exception.new
|
20
|
-
end
|
21
|
-
rescue Exception
|
22
|
-
end
|
23
|
-
expect(ch).to be_closed
|
24
|
-
end
|
25
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
unless ENV["CI"]
|
4
|
-
describe Bunny::Channel, "#basic_publish" do
|
5
|
-
before :all do
|
6
|
-
@connection = Bunny.new(username: "bunny_gem",
|
7
|
-
password: "bunny_password",
|
8
|
-
vhost: "bunny_testbed",
|
9
|
-
write_timeout: 0,
|
10
|
-
read_timeout: 0)
|
11
|
-
@connection.start
|
12
|
-
end
|
13
|
-
|
14
|
-
after :all do
|
15
|
-
@connection.close if @connection.open?
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
context "when publishing thousands of messages" do
|
20
|
-
let(:n) { 2_000 }
|
21
|
-
let(:m) { 10 }
|
22
|
-
|
23
|
-
it "successfully publishers them all" do
|
24
|
-
ch = @connection.create_channel
|
25
|
-
|
26
|
-
q = ch.queue("", exclusive: true)
|
27
|
-
x = ch.default_exchange
|
28
|
-
|
29
|
-
body = "x" * 1024
|
30
|
-
m.times do |i|
|
31
|
-
n.times do
|
32
|
-
x.publish(body, routing_key: q.name)
|
33
|
-
end
|
34
|
-
puts "Published #{i * n} 1K messages..."
|
35
|
-
end
|
36
|
-
|
37
|
-
q.purge
|
38
|
-
ch.close
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Registering 2nd exclusive consumer on queue" do
|
4
|
-
before :all do
|
5
|
-
@connection = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
6
|
-
@connection.start
|
7
|
-
end
|
8
|
-
|
9
|
-
after :each do
|
10
|
-
@connection.close if @connection.open?
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
it "raises a meaningful exception" do
|
15
|
-
xs = []
|
16
|
-
|
17
|
-
ch1 = @connection.create_channel
|
18
|
-
ch2 = @connection.create_channel
|
19
|
-
q1 = ch1.queue("", :auto_delete => true)
|
20
|
-
q2 = ch2.queue(q1.name, :auto_delete => true, :passive => true)
|
21
|
-
|
22
|
-
c1 = q1.subscribe(exclusive: true) do |_, _, payload|
|
23
|
-
xs << payload
|
24
|
-
end
|
25
|
-
sleep 0.1
|
26
|
-
|
27
|
-
expect do
|
28
|
-
q2.subscribe(exclusive: true) do |_, _, _|
|
29
|
-
end
|
30
|
-
end.to raise_error(Bunny::AccessRefused)
|
31
|
-
|
32
|
-
expect(ch1).to be_open
|
33
|
-
expect(ch2).to be_closed
|
34
|
-
|
35
|
-
q1.publish("abc")
|
36
|
-
sleep 0.1
|
37
|
-
|
38
|
-
# verify that the first consumer is fine
|
39
|
-
expect(xs).to eq ["abc"]
|
40
|
-
|
41
|
-
q1.delete
|
42
|
-
end
|
43
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Bunny::Session do
|
4
|
-
context "with unreachable host" do
|
5
|
-
it "raises Bunny::TCPConnectionFailed" do
|
6
|
-
begin
|
7
|
-
conn = Bunny.new(:hostname => "127.0.0.254", :port => 1433)
|
8
|
-
conn.start
|
9
|
-
|
10
|
-
fail "expected 192.192.192.192 to be unreachable"
|
11
|
-
rescue Bunny::TCPConnectionFailed => e
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
unless ENV["CI"]
|
5
|
-
describe "Message framing implementation" do
|
6
|
-
let(:connection) do
|
7
|
-
c = Bunny.new(:user => "bunny_gem",
|
8
|
-
password: "bunny_password",
|
9
|
-
:vhost => "bunny_testbed",
|
10
|
-
:port => ENV.fetch("RABBITMQ_PORT", 5672))
|
11
|
-
c.start
|
12
|
-
c
|
13
|
-
end
|
14
|
-
|
15
|
-
after :each do
|
16
|
-
connection.close if connection.open?
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
context "with payload 272179 bytes in size" do
|
21
|
-
it "successfully frames the message" do
|
22
|
-
ch = connection.create_channel
|
23
|
-
|
24
|
-
q = ch.queue("", exclusive: true)
|
25
|
-
x = ch.default_exchange
|
26
|
-
|
27
|
-
as = ("a" * 272179)
|
28
|
-
x.publish(as, routing_key: q.name, persistent: true)
|
29
|
-
|
30
|
-
sleep(1)
|
31
|
-
expect(q.message_count).to eq 1
|
32
|
-
|
33
|
-
_, _, payload = q.pop
|
34
|
-
expect(payload.bytesize).to eq as.bytesize
|
35
|
-
|
36
|
-
ch.close
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Bunny::Session do
|
5
|
-
let(:connection) do
|
6
|
-
c = Bunny.new(
|
7
|
-
user: 'bunny_gem', password: 'bunny_password',
|
8
|
-
vhost: 'bunny_testbed',
|
9
|
-
port: ENV.fetch('RABBITMQ_PORT', 5672)
|
10
|
-
)
|
11
|
-
c.start
|
12
|
-
c
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'after the connection has been manually closed' do
|
16
|
-
before :each do
|
17
|
-
connection.close
|
18
|
-
end
|
19
|
-
|
20
|
-
after :each do
|
21
|
-
connection.close if connection.open?
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#create_channel' do
|
25
|
-
it 'should raise an exception' do
|
26
|
-
expect {
|
27
|
-
connection.create_channel
|
28
|
-
}.to raise_error(Bunny::ConnectionAlreadyClosed)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Bunny::Session do
|
4
|
-
context 'when retry attempts have been exhausted' do
|
5
|
-
let(:io) { StringIO.new } # keep test output clear
|
6
|
-
|
7
|
-
def create_session
|
8
|
-
described_class.new(
|
9
|
-
host: 'fake.host',
|
10
|
-
recovery_attempts: 0,
|
11
|
-
connection_timeout: 0,
|
12
|
-
network_recovery_interval: 0,
|
13
|
-
logfile: io,
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'closes the session' do
|
18
|
-
session = create_session
|
19
|
-
session.handle_network_failure(StandardError.new)
|
20
|
-
expect(session.closed?).to be true
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'stops the reader loop' do
|
24
|
-
session = create_session
|
25
|
-
reader_loop = session.reader_loop
|
26
|
-
session.handle_network_failure(StandardError.new)
|
27
|
-
expect(reader_loop.stopping?).to be true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/issues/issue78_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
unless ENV["CI"]
|
4
|
-
describe Bunny::Queue, "#subscribe" do
|
5
|
-
before :all do
|
6
|
-
@connection1 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
7
|
-
@connection1.start
|
8
|
-
@connection2 = Bunny.new(:user => "bunny_gem", password: "bunny_password", :vhost => "bunny_testbed")
|
9
|
-
@connection2.start
|
10
|
-
end
|
11
|
-
|
12
|
-
after :all do
|
13
|
-
[@connection1, @connection2].select { |c| !!c }.each do |c|
|
14
|
-
c.close if c.open?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
context "with an empty queue" do
|
20
|
-
it "consumes messages" do
|
21
|
-
delivered_data = []
|
22
|
-
|
23
|
-
ch1 = @connection1.create_channel
|
24
|
-
ch2 = @connection1.create_channel
|
25
|
-
|
26
|
-
q = ch1.queue("", exclusive: true)
|
27
|
-
q.subscribe(manual_ack: false) do |delivery_info, properties, payload|
|
28
|
-
delivered_data << payload
|
29
|
-
end
|
30
|
-
sleep 0.5
|
31
|
-
|
32
|
-
x = ch2.default_exchange
|
33
|
-
x.publish("abc", routing_key: q.name)
|
34
|
-
sleep 0.7
|
35
|
-
|
36
|
-
expect(delivered_data).to eq ["abc"]
|
37
|
-
|
38
|
-
ch1.close
|
39
|
-
ch2.close
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "with a non-empty queue" do
|
44
|
-
let(:queue_name) { "queue#{rand}" }
|
45
|
-
|
46
|
-
it "consumes messages" do
|
47
|
-
delivered_data = []
|
48
|
-
|
49
|
-
ch1 = @connection1.create_channel
|
50
|
-
ch2 = @connection1.create_channel
|
51
|
-
|
52
|
-
q = ch1.queue(queue_name, exclusive: true)
|
53
|
-
x = ch2.default_exchange
|
54
|
-
3.times do |i|
|
55
|
-
x.publish("data#{i}", routing_key: queue_name)
|
56
|
-
end
|
57
|
-
sleep 0.7
|
58
|
-
expect(q.message_count).to eq 3
|
59
|
-
|
60
|
-
q.subscribe(manual_ack: false) do |delivery_info, properties, payload|
|
61
|
-
delivered_data << payload
|
62
|
-
end
|
63
|
-
sleep 0.7
|
64
|
-
|
65
|
-
expect(delivered_data).to eq ["data0", "data1", "data2"]
|
66
|
-
|
67
|
-
ch1.close
|
68
|
-
ch2.close
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|