pebbles-river 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 849ea26964c3aa0eca352aafc7642748c4eb587f
4
- data.tar.gz: f94b8412cffeffc29b4bffcddef89aaf7a7c91d4
3
+ metadata.gz: b095f1ed2b6aff2c1d4916c73503981169c7ac5a
4
+ data.tar.gz: f69bdbd2bc4cef2a857bc84555eb83342b1ed699
5
5
  SHA512:
6
- metadata.gz: 795e37fc7303ae8811a3ee0754090ac6b4c4938cb1d51e760dc7c76fecf95dd00651ab400e5ace6370939d0760b79af60486bbd2508b7c1d82fb4ad49972b8ec
7
- data.tar.gz: bfdd4900bb2eb74905cc3b6e0eab54251910c0fab32f49c750ca0ec24b3715ea351e72d593f3cbbfec9f7ff798817c28c515d689e4387ae836e50b94c7da580b
6
+ metadata.gz: e8e8da724df5dcaafd4d1f1acdb9a0b5dc7fa2a93e2cb01af110f5522a42b203bc011e8c2953f4f50057840cee1a9e0d1aa6a9f659c99f01a80926c67def385a
7
+ data.tar.gz: 49e9212ea4c0b3db87894dc15f6d9b2769e8f947f164cdcc1213dd7bf5d71321c9f27de4baccf078e0da9b85b64684baaadea8cbf9fac4fe95fe162ecaf9246c
@@ -46,9 +46,7 @@ module Pebbles
46
46
  if @channel
47
47
  begin
48
48
  @channel.close
49
- rescue Bunny::ChannelAlreadyClosed
50
- # Ignore
51
- rescue *CONNECTION_EXCEPTIONS
49
+ rescue Bunny::Exception
52
50
  # Ignore
53
51
  end
54
52
  @channel = nil
@@ -56,7 +54,7 @@ module Pebbles
56
54
  if @session
57
55
  begin
58
56
  @session.stop
59
- rescue *CONNECTION_EXCEPTIONS
57
+ rescue Bunny::Exception
60
58
  # Ignore
61
59
  end
62
60
  @session = nil
@@ -112,9 +110,9 @@ module Pebbles
112
110
  retry_count = 0
113
111
  begin
114
112
  yield
115
- rescue *CONNECTION_EXCEPTIONS => exception
113
+ rescue Bunny::Exception => e
116
114
  disconnect
117
- last_exception = exception
115
+ last_exception = e
118
116
  retry_count += 1
119
117
  backoff(retry_count)
120
118
  retry
@@ -1,5 +1,5 @@
1
1
  module Pebbles
2
2
  module River
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  end
5
5
  end
@@ -136,23 +136,23 @@ module Pebbles
136
136
  def process_message(delivery_info, properties, content)
137
137
  begin
138
138
  message = Message.new(content, delivery_info, queue)
139
- rescue => exception
139
+ rescue => e
140
140
  ignore_exceptions do
141
141
  reject(delivery_info)
142
142
  end
143
- raise exception
143
+ raise e
144
144
  else
145
145
  begin
146
146
  result = @handler.call(message)
147
- rescue *CONNECTION_EXCEPTIONS
147
+ rescue Bunny::Exception
148
148
  raise
149
- rescue => exception
149
+ rescue => e
150
150
  if @managed_acking
151
151
  ignore_exceptions do
152
152
  reject(delivery_info)
153
153
  end
154
154
  end
155
- raise exception
155
+ raise e
156
156
  else
157
157
  if @managed_acking
158
158
  case result
@@ -177,26 +177,19 @@ module Pebbles
177
177
  def with_exceptions(&block)
178
178
  begin
179
179
  yield
180
- rescue *CONNECTION_EXCEPTIONS => exception
181
- if @logger
182
- @logger.error("Connection error (#{exception.class}): #{exception}")
183
- end
184
- @rate_limiter.increment
185
- @queue = nil
186
- @river.disconnect
180
+ rescue Bunny::Exception
181
+ raise
187
182
  rescue Timeout::Error
188
183
  if @logger
189
184
  @logger.error("Timeout polling for messages (ignoring)")
190
185
  end
191
- rescue => exception
186
+ rescue => e
192
187
  if @logger
193
- @logger.error("Exception (#{exception.class}) while handling message: #{exception}")
188
+ @logger.error("Exception (#{e.class}) while handling message: #{e}")
194
189
  end
195
-
196
190
  @rate_limiter.increment
197
-
198
191
  ignore_exceptions do
199
- @on_exception.call(exception)
192
+ @on_exception.call(e)
200
193
  end
201
194
  end
202
195
  end
data/lib/pebbles/river.rb CHANGED
@@ -18,12 +18,6 @@ require_relative "river/daemon_helper"
18
18
 
19
19
  module Pebbles::River
20
20
 
21
- CONNECTION_EXCEPTIONS = [
22
- Bunny::Exception,
23
- # These should be caught by Bunny, but apparently aren't.
24
- Errno::ECONNRESET
25
- ].freeze
26
-
27
21
  def self.rabbitmq_options
28
22
  @rabbitmq_options ||= {}.freeze
29
23
  end
@@ -11,17 +11,6 @@ describe Pebbles::River::River do
11
11
  Pebbles::River::River.new(environment: 'whatever')
12
12
  end
13
13
 
14
- CONNECTION_EXCEPTIONS = [
15
- Bunny::ConnectionError,
16
- Bunny::ConnectionClosedError,
17
- Bunny::ChannelAlreadyClosed,
18
- Bunny::ForcedChannelCloseError,
19
- Bunny::ForcedConnectionCloseError,
20
- Bunny::ServerDownError,
21
- Bunny::ProtocolError,
22
- Errno::ECONNRESET
23
- ]
24
-
25
14
  after(:each) do
26
15
  if (channel = subject.channel)
27
16
  channel.queues.each do |name, queue|
@@ -100,73 +89,6 @@ describe Pebbles::River::River do
100
89
  JSON.parse(payload)['uid'].should eq('klass:path$1')
101
90
  end
102
91
 
103
- CONNECTION_EXCEPTIONS.each do |exception_class|
104
- context "on temporary failure with #{exception_class}" do
105
- it "reconnects and retries sending until success" do
106
- exchange = double('exchange')
107
-
108
- count = 0
109
- exchange.stub(:publish) do
110
- count += 1
111
- if count < 3
112
- raise create_exception(exception_class)
113
- end
114
- end
115
-
116
- subject.stub(:connect) { }
117
- subject.stub(:exchange) { exchange }
118
- subject.stub(:sleep) { }
119
- Timeout.stub(:timeout) { |&block|
120
- block.call
121
- }
122
- expect(Timeout).to receive(:timeout).at_least(1).times
123
-
124
- expect(subject).to receive(:sleep).at_least(2).times
125
- expect(subject).to receive(:connect).exactly(3).times
126
- expect(subject).to receive(:disconnect).exactly(3).times
127
-
128
- expect(exchange).to receive(:publish).at_least(2).times
129
-
130
- subject.publish(event: 'explode', uid: 'thing:rspec$1')
131
- end
132
- end
133
- end
134
-
135
- CONNECTION_EXCEPTIONS.each do |exception_class|
136
- context "on permanent failure with #{exception_class}" do
137
- it "retries with exponential backoff until timeout and gives up with SendFailure" do
138
- exchange = double('exchange')
139
- exchange.stub(:publish) do
140
- raise create_exception(exception_class)
141
- end
142
- subject.stub(:exchange) { exchange }
143
-
144
- count, sleeps = 0, []
145
- subject.stub(:sleep) { |t|
146
- count += 1
147
- if count >= 10
148
- raise Timeout::Error
149
- end
150
- sleeps.push(t)
151
- }
152
-
153
- Timeout.stub(:timeout) { |&block|
154
- block.call
155
- }
156
- expect(Timeout).to receive(:timeout).at_least(1).times
157
-
158
- expect(subject).to receive(:disconnect).at_least(11).times
159
-
160
- expect(-> { subject.publish({event: 'explode', uid: 'thing:rspec$1'})}).to raise_error do |e|
161
- expect(e).to be_instance_of Pebbles::River::SendFailure
162
- expect(e.connection_exception.class).to eq exception_class
163
- end
164
-
165
- expect(sleeps[0, 9]).to eq [1, 2, 4, 8, 10, 10, 10, 10, 10]
166
- end
167
- end
168
- end
169
-
170
92
  context 'on connection timeout' do
171
93
  it "gives up with SendFailure" do
172
94
  exchange = double('exchange')
@@ -203,71 +203,36 @@ describe Worker do
203
203
  end
204
204
  end
205
205
 
206
- [
207
- Bunny::ConnectionError,
208
- Bunny::ChannelAlreadyClosed,
209
- Bunny::ForcedChannelCloseError,
210
- Bunny::ForcedConnectionCloseError,
211
- Bunny::ServerDownError,
212
- Bunny::ProtocolError,
213
- Errno::ECONNRESET
214
- ].each do |exception_class|
215
- context "connection exception #{exception_class}" do
216
- let :exception do
217
- create_exception(exception_class)
218
- end
219
-
220
- let :handler do
221
- handler = double('handler')
222
- allow(handler).to receive(:call) {
223
- raise exception
224
- }
225
- handler
226
- end
227
-
228
- it "performs connection reset on #{exception_class}" do
229
- expect(handler).to receive(:call).with(message)
206
+ context "connection exception" do
207
+ let :exception do
208
+ Bunny::ConnectionError.new("error!")
209
+ end
230
210
 
231
- expect(river).to receive(:connected?).with(no_args).at_least(1).times
232
- expect(river).to_not receive(:connect)
233
- expect(river).to receive(:queue).with({name: 'foo'})
234
- expect(river).to receive(:disconnect).at_least(1).times
211
+ let :handler do
212
+ handler = double('handler')
213
+ allow(handler).to receive(:call) {
214
+ raise exception
215
+ }
216
+ handler
217
+ end
235
218
 
219
+ it "re-raises exception" do
220
+ expect(handler).to receive(:call).with(message)
221
+ expect(->() {
236
222
  subject.new(handler, queue: {name: 'foo'}).run_once
237
- end
238
-
239
- it "does not call #on_exception on connection error" do
240
- on_exception_callback = double('on_connection_error')
241
- on_exception_callback.stub(:call) { }
242
- expect(on_exception_callback).to_not receive(:call)
243
-
244
- expect(handler).to receive(:call).at_least(1).times
245
-
246
- expect(river).to receive(:connected?).with(no_args).at_least(1).times
247
- expect(river).to_not receive(:connect)
248
- expect(river).to receive(:disconnect).at_least(1).times
223
+ }).to raise_error(Bunny::ConnectionError)
224
+ end
249
225
 
226
+ it "does not call #on_exception on connection error" do
227
+ on_exception_callback = double('on_connection_error')
228
+ on_exception_callback.stub(:call) { }
229
+ expect(on_exception_callback).to_not receive(:call)
230
+ expect(handler).to receive(:call).at_least(1).times
231
+ expect(->() {
250
232
  subject.new(handler,
251
233
  queue: {name: 'foo'},
252
234
  on_exception: on_exception_callback).run_once
253
- end
254
-
255
- it "logs error to logger" do
256
- expect(handler).to receive(:call).with(message)
257
-
258
- logger = double('logger')
259
- logger.stub(:error) { }
260
-
261
- # TODO: Test exception contents here
262
- expect(logger).to receive(:error).
263
- with(/.*/).at_least(1).times
264
-
265
- river.stub(:disconnect)
266
-
267
- subject.new(handler,
268
- queue: {name: 'foo'},
269
- logger: logger).run_once
270
- end
235
+ }).to raise_error(Bunny::ConnectionError)
271
236
  end
272
237
  end
273
238
 
data/spec/spec_helper.rb CHANGED
@@ -8,21 +8,6 @@ SimpleCov.start
8
8
 
9
9
  require_relative '../lib/pebbles/river'
10
10
 
11
- module SpecHelpers
12
- def create_exception(exception_class)
13
- # TODO: Using #allocate here because Bunny has a whole bunch
14
- # of exceptions; the one comparison against ECONNRESET is sad
15
- # and could be generalized
16
- if exception_class == Errno::ECONNRESET
17
- raise exception_class.new
18
- else
19
- raise exception_class.allocate
20
- end
21
- end
22
- end
23
-
24
11
  RSpec.configure do |config|
25
12
  config.mock_with :rspec
26
- config.include SpecHelpers
27
13
  end
28
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebbles-river
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Staubo