iron_mq 4.1.0 → 5.0.1

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: 1f1f8bd2435758c3f0e785860745e53693f420dd
4
- data.tar.gz: 8c528651911fbab189d39f2517a6916ccff76455
3
+ metadata.gz: de99bdc9d622017003d1e102420d9c0d28cfb18e
4
+ data.tar.gz: 5c83be6f01552a73dcd95d8be0410221a4dd500d
5
5
  SHA512:
6
- metadata.gz: dff00f9dc21895c394d2b0b03fd37e4cc3994d80b980ac9ac1e56c4169c07b540f42df0a07ae02eb3015261695de0bfeb8bd55655ec2024c092d033122254493
7
- data.tar.gz: f55c54ab596adc06964a1209b7ed5bef4c09c4ce4013dcedeec0a6d234489c8abbd28834acfd7320d06f50704ae7fd232b4b7990ac35d064c77337e109efc762
6
+ metadata.gz: f382fa201f071244adf25be870e6f575a711140a15e2c4b44a284365e92a78045112800868bb0ef00a904fd59dadf2b4b9aedf5c54bb367c0c7aed0eb292476a
7
+ data.tar.gz: a061b8a98b4271f93d063d058a1edf5da79e2d39206edeeaca78e6ac7dbb5ebb24848c104b84f16d08022bc941879ea4d1bef9c758441095815d3f777efac77f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iron_mq (4.0.3)
4
+ iron_mq (5.0.0)
5
5
  iron_core (>= 0.5.1)
6
6
 
7
7
  GEM
@@ -17,26 +17,26 @@ GEM
17
17
  concur
18
18
  iron_core (1.0.3)
19
19
  rest (>= 2.6.4)
20
- iron_worker_ng (1.0.4)
20
+ iron_worker_ng (1.2.0)
21
21
  bundler
22
22
  iron_core (>= 1.0.0)
23
- rubyzip (= 0.9.9)
23
+ rubyzip (>= 1.0.0)
24
24
  mime-types (1.25.1)
25
- minitest (5.2.1)
26
- net-http-persistent (2.9)
25
+ minitest (5.2.3)
26
+ net-http-persistent (2.9.4)
27
27
  netrc (0.7.7)
28
28
  quicky (0.4.0)
29
29
  rake (10.1.1)
30
- rest (2.7.0)
31
- net-http-persistent
30
+ rest (2.7.1)
31
+ net-http-persistent (>= 2.9.1)
32
32
  rest_client (>= 1.7.1)
33
33
  rest_client (1.7.2)
34
34
  netrc (~> 0.7.7)
35
- rubyzip (0.9.9)
35
+ rubyzip (1.1.0)
36
36
  test-unit (2.5.5)
37
37
  typhoeus (0.6.7)
38
38
  ethon (~> 0.6.2)
39
- uber_config (1.1.0)
39
+ uber_config (1.1.1)
40
40
 
41
41
  PLATFORMS
42
42
  ruby
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014, Iron.io, Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the documentation
10
+ and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19
+ OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -4,6 +4,8 @@ IronMQ Ruby Client
4
4
  The [full API documentation is here](http://dev.iron.io/mq/reference/api/) and this client tries to stick to the API as
5
5
  much as possible so if you see an option in the API docs, you can use it in the methods below.
6
6
 
7
+ **WARNING: Version 5+ has some small breaking changes. Version 4 ignored 404's on delete operations, Version
8
+ 5 will now raise exceptions.
7
9
 
8
10
  ## Getting Started
9
11
 
data/iron_mq.gemspec CHANGED
@@ -6,6 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.description = "Ruby client for IronMQ by www.iron.io"
7
7
  gem.summary = "Ruby client for IronMQ by www.iron.io"
8
8
  gem.homepage = "https://github.com/iron-io/iron_mq_ruby"
9
+ gem.license = "BSD-2-Clause"
9
10
 
10
11
  gem.files = `git ls-files`.split($\)
11
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/iron_mq/alert.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  module IronMQ
2
2
 
3
3
  class Alert
4
- # `options` was kept for backward compatibility
5
- attr_accessor :options
4
+ attr_reader :raw
6
5
 
7
- def initialize(queue, alert_hash, options = {})
6
+ def initialize(queue, alert_hash)
8
7
  @queue = queue
9
8
  @raw = alert_hash
10
- @options = options
11
9
  end
12
10
 
13
11
  def id
@@ -32,17 +30,20 @@ module IronMQ
32
30
  @raw['direction']
33
31
  end
34
32
 
35
- # `options` was kept for backward compatibility
36
- def delete(options = {})
37
- @message.call_api_and_parse_response(:delete, path)
33
+ def snooze
34
+ @raw['snooze']
35
+ end
36
+
37
+ def delete
38
+ @queue.call_api_and_parse_response(:delete, path)
38
39
  rescue Rest::HttpError => ex
39
- if ex.code == 404
40
- IronCore::Logger.info('IronMQ', 'Delete got 404, safe to ignore.')
41
- # return ResponseBase as normal
42
- ResponseBase.new({'msg' => 'Deleted'}, 404)
43
- else
40
+ #if ex.code == 404
41
+ # IronCore::Logger.info('IronMQ', 'Delete got 404, safe to ignore.')
42
+ # # return ResponseBase as normal
43
+ # ResponseBase.new({'msg' => 'Deleted'}, 404)
44
+ #else
44
45
  raise ex
45
- end
46
+ #end
46
47
  end
47
48
 
48
49
  alias_method :acknowledge, :delete
@@ -48,13 +48,13 @@ module IronMQ
48
48
  def delete
49
49
  call_api_and_parse_response(:delete)
50
50
  rescue Rest::HttpError => ex
51
- if ex.code == 404
52
- Rest.logger.info("Delete got 404, safe to ignore.")
53
- # return ResponseBase as normal
54
- ResponseBase.new({"msg" => "Deleted"}, 404)
55
- else
51
+ #if ex.code == 404
52
+ # Rest.logger.info("Delete got 404, safe to ignore.")
53
+ # # return ResponseBase as normal
54
+ # ResponseBase.new({"msg" => "Deleted"}, 404)
55
+ #else
56
56
  raise ex
57
- end
57
+ #end
58
58
  end
59
59
 
60
60
  def call_api_and_parse_response(meth, ext_path = "", options = {}, instantiate = true)
@@ -71,13 +71,13 @@ module IronMQ
71
71
  @raw = nil
72
72
  return r
73
73
  rescue Rest::HttpError => ex
74
- if ex.code == 404
75
- Rest.logger.info("Delete got 404, safe to ignore.")
76
- # return ResponseBase as normal
77
- ResponseBase.new({"msg" => "Deleted"}, 404)
78
- else
74
+ #if ex.code == 404
75
+ # Rest.logger.info("Delete got 404, safe to ignore.")
76
+ # # return ResponseBase as normal
77
+ # ResponseBase.new({"msg" => "Deleted"}, 404)
78
+ #else
79
79
  raise ex
80
- end
80
+ #end
81
81
  end
82
82
 
83
83
  # Backward compatibility
@@ -122,18 +122,26 @@ module IronMQ
122
122
  []
123
123
  end
124
124
 
125
- def add_alert(alert = {})
125
+ def add_alert(alert)
126
126
  add_alerts([alert])
127
127
  end
128
128
 
129
129
  def add_alerts(alerts)
130
- call_api_and_parse_response(:post, "/alerts", :alerts => alerts)
130
+ call_api_and_parse_response(:post, '/alerts', :alerts => alerts)
131
+ end
132
+
133
+ def remove_alerts(alerts)
134
+ call_api_and_parse_response(:delete, '/alerts', :alerts => alerts)
135
+ end
136
+
137
+ def remove_alert(alert)
138
+ remove_alerts([alert])
131
139
  end
132
140
 
133
141
  def alerts
134
142
  load
135
- return nil unless @raw["alerts"]
136
- to_alerts(@raw["alerts"])
143
+ return nil unless @raw['alerts']
144
+ to_alerts(@raw['alerts'])
137
145
  end
138
146
 
139
147
  def post_messages(payload, options = {})
@@ -22,13 +22,13 @@ module IronMQ
22
22
  def delete(options = {})
23
23
  @message.call_api_and_parse_response(:delete, path)
24
24
  rescue Rest::HttpError => ex
25
- if ex.code == 404
26
- Rest.logger.info("Delete got 404, safe to ignore.")
27
- # return ResponseBase as normal
28
- ResponseBase.new({"msg" => "Deleted"}, 404)
29
- else
25
+ #if ex.code == 404
26
+ # Rest.logger.info("Delete got 404, safe to ignore.")
27
+ # # return ResponseBase as normal
28
+ # ResponseBase.new({"msg" => "Deleted"}, 404)
29
+ #else
30
30
  raise ex
31
- end
31
+ #end
32
32
  end
33
33
 
34
34
  alias_method :acknowledge, :delete
@@ -1,4 +1,4 @@
1
1
  module IronMQ
2
- VERSION = "4.1.0"
2
+ VERSION = "5.0.1"
3
3
  end
4
4
 
data/test/test_alerts.rb CHANGED
@@ -10,10 +10,89 @@ class TestAlerts < TestBase
10
10
  return if @skip # bypass these tests if rackspace
11
11
  end
12
12
 
13
+ def test_configuration
14
+ q_name = 'bad-alerts-params'
15
+ queue = @client.queue q_name
16
+ delete_queues queue
17
+
18
+ # no configuration
19
+ alert = {}
20
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
21
+
22
+ # only type is specified
23
+ alert[:type] = 'fixed'
24
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
25
+
26
+ # type and trigger value specified
27
+ alert[:trigger] = 30
28
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
29
+
30
+ # type, trigger, and direction
31
+ alert[:direction] = 'asc'
32
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
33
+
34
+ # type, trigger, direction, and alert queue name - alright
35
+ aq_name = 'bad-alerts-params-alerts'
36
+ alert[:queue] = aq_name
37
+ assert_nothing_raised(Rest::HttpError) { queue.add_alert(alert) }
38
+
39
+ # type, trigger, direction, queue name, and snooze - alright
40
+ alert[:snooze] = 8
41
+ assert_nothing_raised(Rest::HttpError) { queue.add_alert(alert) }
42
+
43
+ # wrong snooze
44
+ alert[:snooze] = -13
45
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
46
+
47
+ alert[:snooze] = '1234'
48
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
49
+
50
+ # wrong type
51
+ alert[:snooze] = 0
52
+ alert[:type] = 'wrong'
53
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
54
+
55
+ # wrong trigger
56
+ alert[:type] = 'progressive'
57
+ alert[:trigger] = 'c'
58
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
59
+
60
+ # wrong direction
61
+ alert[:trigger] = 30
62
+ alert[:direction] = 'both'
63
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
64
+
65
+ # delete queue to clear
66
+ delete_queues queue
67
+
68
+ # Test max alerts number
69
+ alert[:direction] = 'asc'
70
+ # insert 6 alerts
71
+ assert_raise(Rest::HttpError) { queue.add_alerts(Array.new(6, alert)) }
72
+
73
+ queue.add_alerts(Array.new(5, alert))
74
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
75
+
76
+ delete_queues queue
77
+
78
+ # Cyclic alerts tests
79
+ # Progressive alert posts to its queue (queue is the same as alert queue)
80
+ alert[:queue] = q_name
81
+ alert[:type] = 'progressive'
82
+ assert_raise(Rest::HttpError) { queue.add_alert(alert) }
83
+
84
+ # Q1 progressive alert posts to Q2, Q2 progressive alert posts to Q1
85
+ a_queue = @client.queue aq_name
86
+ queue.add_alert(alert.merge({:queue => aq_name}))
87
+ assert_raise(Rest::HttpError) do
88
+ a_queue.add_alert(alert.merge({:queue => q_name}))
89
+ end
90
+ end
91
+
13
92
  def test_size_alerts
14
93
  return if @skip
15
94
 
16
- type = 'size'
95
+ type = 'fixed'
17
96
  trigger = 10
18
97
  # Test size alets, direction is ascending
19
98
  queue, alert_queue = clear_queue_add_alert(type, trigger, 'asc')
@@ -23,11 +102,11 @@ class TestAlerts < TestBase
23
102
 
24
103
  # must not trigger alert, queue size will be trigger + 13
25
104
  post_messages(queue, 10)
26
- assert_equal 1, get_queue_size(alert_queue)
105
+ assert_queue_size 1, alert_queue
27
106
 
28
107
  # must not trigger alert, queue size will be trigger - 3
29
108
  delete_messages(queue, 16)
30
- assert_equal 1, get_queue_size(alert_queue)
109
+ assert_queue_size 1, alert_queue
31
110
 
32
111
  trigger_alert(queue, alert_queue, trigger)
33
112
 
@@ -38,38 +117,65 @@ class TestAlerts < TestBase
38
117
 
39
118
  # must not trigger descending alert
40
119
  post_messages(queue, 15)
41
- assert_equal 0, get_queue_size(alert_queue)
120
+ assert_queue_size 0, alert_queue
42
121
 
43
122
  # will remove 5 msgs, queue size will be 10
44
123
  trigger_alert(queue, alert_queue, trigger)
45
124
 
46
125
  # must not trigger alert
47
126
  post_messages(queue, 12)
48
- assert_equal 1, get_queue_size(alert_queue)
127
+ assert_queue_size 1, alert_queue
49
128
 
50
129
  trigger_alert(queue, alert_queue, trigger)
51
130
 
52
131
  # must not trigger alert
53
132
  delete_messages(queue, 8)
54
- assert_equal 2, get_queue_size(alert_queue)
133
+ assert_queue_size 2, alert_queue
55
134
 
56
135
  delete_queues(queue, alert_queue)
57
136
 
58
- # Test size alerts, direction is "both"
59
- queue, alert_queue = clear_queue_add_alert(type, trigger, 'both')
137
+ # test ascending alert with snooze
138
+ snooze = 10
139
+ trigger = 10
140
+ queue, alert_queue = clear_queue_add_alert(type, trigger, 'asc', snooze)
60
141
 
61
- # trigger ascending alert
62
- trigger_alert(queue, alert_queue, trigger)
142
+ # Trigger alert
143
+ post_messages(queue, trigger + 1)
144
+ to_time = Time.now + snooze - 4
145
+ assert_queue_size 1, alert_queue
63
146
 
64
- # must not trigger alert
65
- post_messages(queue, 8)
66
- assert_equal 1, get_queue_size(alert_queue)
147
+ while (lambda { Time.now }).call < to_time do
148
+ delete_messages(queue, 2) # queeu size is `trigger - 1`
149
+ post_messages(queue, 2) # size is `trigger + 1`
150
+ assert_queue_size 1, alert_queue
151
+ end
152
+ sleep 4
67
153
 
68
- # trigger descending alert, queue size will be trigger - 3
69
- trigger_alert(queue, alert_queue, trigger, 3)
154
+ delete_messages(queue, 2) # queeu size is `trigger - 1`
155
+ post_messages(queue, 2) # size is `trigger - 1`
156
+ assert_queue_size 2, alert_queue
70
157
 
71
- # trigger ascending alert, queue size will be trigger + 3
72
- trigger_alert(queue, alert_queue, trigger, 3)
158
+ delete_queues(queue, alert_queue)
159
+
160
+ # test descending alert with snooze
161
+ queue, alert_queue = clear_queue_add_alert(type, trigger, 'desc', snooze)
162
+
163
+ # Trigger alert
164
+ post_messages(queue, trigger + 1)
165
+ delete_messages(queue, 2)
166
+ to_time = Time.now + snooze - 4
167
+ assert_queue_size 1, alert_queue
168
+
169
+ while (lambda { Time.now }).call < to_time do
170
+ post_messages(queue, 2) # queeu size is `trigger + 1`
171
+ delete_messages(queue, 2) # size is `trigger - 1`
172
+ assert_queue_size 1, alert_queue
173
+ end
174
+ sleep 4
175
+
176
+ post_messages(queue, 2) # size is `trigger + 1`
177
+ delete_messages(queue, 2) # queeu size is `trigger - 1`
178
+ assert_queue_size 2, alert_queue
73
179
 
74
180
  delete_queues(queue, alert_queue)
75
181
  end
@@ -87,7 +193,7 @@ class TestAlerts < TestBase
87
193
 
88
194
  # Must not trigger alerts
89
195
  delete_messages(queue, 15)
90
- assert_equal 3, get_queue_size(alert_queue)
196
+ assert_queue_size 3, alert_queue
91
197
 
92
198
  trig = (get_queue_size(queue) / trigger.to_f).ceil * trigger
93
199
  trigger_alert(queue, alert_queue, trig)
@@ -102,61 +208,102 @@ class TestAlerts < TestBase
102
208
 
103
209
  # must not trigger alert
104
210
  post_messages(queue, 25)
105
- assert_equal 0, get_queue_size(alert_queue)
211
+ assert_queue_size 0, alert_queue
106
212
 
107
213
  # trigger descending alert twice
108
214
  2.downto(1) { |n| trigger_alert(queue, alert_queue, n * trigger) }
109
215
 
110
216
  # must not trigger alert at size of 0
111
217
  delete_messages(queue, 5)
112
- assert_equal 2, get_queue_size(alert_queue)
218
+ assert_queue_size 2, alert_queue
113
219
 
114
220
  # must not trigger alert
115
221
  post_messages(queue, 15)
116
- assert_equal 2, get_queue_size(alert_queue)
222
+ assert_queue_size 2, alert_queue
117
223
 
118
224
  delete_queues(queue, alert_queue)
119
225
 
120
- # Test "both" direction progressive alerts
121
- queue, alert_queue = clear_queue_add_alert(type, trigger, 'both')
226
+ # test ascending alert with snooze
227
+ snooze = 10
228
+ trigger = 3
229
+ queue, alert_queue = clear_queue_add_alert(type, trigger, 'asc', snooze)
230
+
231
+ # Trigger alert
232
+ post_messages(queue, trigger + 1)
233
+ # Get current time as snooze start time
234
+ to_time = Time.now + snooze - 4
235
+ # Check queue for alert
236
+ assert_queue_size 1, alert_queue
237
+
238
+ while (lambda { Time.now }).call < to_time do
239
+ # will trigger alert if snooze does not work
240
+ post_messages(queue, trigger + 1)
241
+ # but must not trigger
242
+ assert_queue_size 1, alert_queue
243
+ end
244
+ sleep 4
122
245
 
123
- trigger_alert(queue, alert_queue, trigger, 2)
124
- trigger_alert(queue, alert_queue, 2 * trigger) # queue size = 2 * trigger
246
+ # Trigger alert again
247
+ post_messages(queue, trigger + 1)
248
+ assert_queue_size 2, alert_queue
125
249
 
126
- # must not trigger descending alert
127
- delete_messages(queue, trigger / 2)
128
- assert_equal 2, get_queue_size(alert_queue)
250
+ delete_queues(queue, alert_queue)
129
251
 
130
- # trigger descending alert, queue size will be trigger - 3
131
- trigger_alert(queue, alert_queue, trigger, 3)
252
+ # test descending alert with snooze
253
+ queue, alert_queue = clear_queue_add_alert(type, 2, 'desc', snooze)
132
254
 
133
- # trigger ascending alert, queue size will be trigger + 5
134
- trigger_alert(queue, alert_queue, trigger, 5)
255
+ # Does not trigger alert
256
+ post_messages(queue, 20 * trigger)
257
+ to_time = Time.now + snooze - 4
135
258
 
136
- # must not trigger alerts below, queue size will be 2 * trigger - 1
137
- post_messages(queue, trigger - 5 - 1)
138
- assert_equal 4, get_queue_size(alert_queue)
259
+ while (lambda { Time.now }).call < to_time do
260
+ delete_messages(queue, trigger + 1)
261
+ assert_queue_size 1, alert_queue
262
+ break if get_queue_size(queue) <= trigger
263
+ end
264
+ sleep 4
139
265
 
140
- # one message before trigger value
141
- delete_messages(queue, trigger - 2)
142
- assert_equal 4, get_queue_size(alert_queue)
266
+ post_messages(queue, trigger + 1)
267
+ delete_messages(queue, trigger)
268
+ assert_queue_size 2, alert_queue
143
269
 
144
270
  delete_queues(queue, alert_queue)
145
271
  end
146
272
 
273
+ def test_snooze_concurrent
274
+ assert false, 'NOT IMPLEMENTED'
275
+ end
276
+
147
277
  def post_messages(queue, n)
148
- queue.post(Array.new(n, { :body => 'message' }))
149
- sleep 1
278
+ per_100, last_n = (n > 100) ? [n / 100, n % 100] : [0, n]
279
+
280
+ per_100.times { queue.post(Array.new(100, { :body => 'message' })) }
281
+
282
+ queue.post(Array.new(last_n, { :body => 'message' })) if last_n > 0
150
283
  end
151
284
 
152
285
  def delete_messages(queue, n)
153
- msgs = queue.get(:n => n)
154
- [msgs].flatten.each { |msg| msg.delete }
155
- sleep 1
286
+ per_100, last_n = (n > 100) ? [n / 100, n % 100] : [0, n]
287
+
288
+ per_100.times { [queue.get(:n => last_n)].flatten.each { |msg| msg.delete } }
289
+
290
+ [queue.get(:n => last_n)].flatten.each { |msg| msg.delete } if last_n > 0
156
291
  end
157
292
 
158
293
  def delete_queues(*queues)
159
- queues.each { |q| q.delete_queue }
294
+ queues.each do |q|
295
+ begin
296
+ q.delete_queue
297
+ rescue Rest::HttpError => ex
298
+ if ex.code == 404
299
+ Rest.logger.info("Delete queue got 404, ignoring.")
300
+ # return ResponseBase as normal
301
+ return nil
302
+ else
303
+ raise ex
304
+ end
305
+ end
306
+ end
160
307
  end
161
308
 
162
309
  def trigger_alert(queue, alert_queue, trigger, overhead = 0)
@@ -176,22 +323,22 @@ class TestAlerts < TestBase
176
323
  puts "Try to trigger descending alert... delete #{nmsgs} messages"
177
324
  delete_messages(queue, nmsgs)
178
325
  end
179
- assert_equal aq_size, get_queue_size(alert_queue)
326
+ assert_queue_size aq_size, alert_queue, 'Alert is triggered, but must not be'
180
327
 
181
328
  if qsize < trigger
182
- puts "Post more #{1 + overhead} messages"
329
+ puts "Post #{1 + overhead} more message(s)"
183
330
  post_messages(queue, 1 + overhead)
184
331
  else
185
- puts "Delete more #{1 + overhead} messages"
332
+ puts "Delete #{1 + overhead} more message(s)"
186
333
  delete_messages(queue, 1 + overhead)
187
334
  end
188
- assert_equal aq_size + 1, get_queue_size(alert_queue)
335
+ assert_queue_size aq_size + 1, alert_queue, 'Alert is not triggered, but must be'
189
336
  end
190
337
 
191
- def clear_queue_add_alert(type, trigger, direction)
338
+ def clear_queue_add_alert(type, trigger, direction, snooze = nil)
192
339
  puts "clear_queue_add_alert(), called at #{caller[0]}"
193
340
 
194
- qname = "#{type}-#{direction}-#{trigger}"
341
+ qname = "#{type}-#{direction}-#{trigger}-#{snooze || 'no_snooze'}"
195
342
  alert_qname = "#{qname}-alerts"
196
343
 
197
344
  queue = @client.queue(qname)
@@ -200,8 +347,11 @@ class TestAlerts < TestBase
200
347
  delete_queues(queue, alert_queue)
201
348
  # todo: should :queue be called something else,
202
349
  # like alert_queue? or url and have to use ironmq:// url?
203
- r = queue.add_alert({ :type => type, :trigger => trigger,
204
- :queue => alert_qname, :direction => direction })
350
+ r = queue.add_alert({ :type => type,
351
+ :trigger => trigger,
352
+ :queue => alert_qname,
353
+ :direction => direction,
354
+ :snooze => snooze.to_i })
205
355
  #p r
206
356
 
207
357
  alerts = queue.alerts
@@ -226,4 +376,10 @@ class TestAlerts < TestBase
226
376
  end
227
377
  end
228
378
 
379
+ def assert_queue_size(size, queue, msg = nil)
380
+ puts "assert_queue_size(), called at #{caller[0]}"
381
+ sleep 1
382
+ assert_equal size, get_queue_size(queue), msg.to_s
383
+ end
384
+
229
385
  end
data/test/test_iron_mq.rb CHANGED
@@ -674,5 +674,22 @@ class IronMQTests < TestBase
674
674
  q.update_queue(:retries => 10)
675
675
  assert_equal 'unicast', q.reload.push_type
676
676
  end
677
+
678
+ def test_dequeue_delete
679
+ queue_name = "test_dequeue_delete_#{Time.now.to_i}"
680
+ clear_queue(queue_name)
681
+ queue = @client.queue(queue_name)
682
+ v = "hello thou shalt only see me once"
683
+ queue.post(v)
684
+ msg = queue.get(delete: 1, timeout: 30)
685
+ assert_equal msg.body, "hello thou shalt only see me once"
686
+ sleep 1
687
+ # get the queue again
688
+ queue = @client.queue(queue_name)
689
+ assert_equal 0, queue.size
690
+ sleep 31
691
+ msg = queue.get
692
+ assert_equal nil, msg
693
+ end
677
694
  end
678
695
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_mq
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Yantsevich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-20 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: iron_core
@@ -176,6 +176,7 @@ files:
176
176
  - .gitignore
177
177
  - Gemfile
178
178
  - Gemfile.lock
179
+ - LICENSE
179
180
  - README.md
180
181
  - Rakefile
181
182
  - iron_mq.gemspec
@@ -201,7 +202,8 @@ files:
201
202
  - test/test_push_queues.rb
202
203
  - test/tmp.rb
203
204
  homepage: https://github.com/iron-io/iron_mq_ruby
204
- licenses: []
205
+ licenses:
206
+ - BSD-2-Clause
205
207
  metadata: {}
206
208
  post_install_message:
207
209
  rdoc_options: []
@@ -219,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
221
  version: 1.3.6
220
222
  requirements: []
221
223
  rubyforge_project:
222
- rubygems_version: 2.0.3
224
+ rubygems_version: 2.1.11
223
225
  signing_key:
224
226
  specification_version: 4
225
227
  summary: Ruby client for IronMQ by www.iron.io