iron_mq 5.0.1 → 6.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,12 +29,12 @@ class TestWorkerSubscribers < TestBase
29
29
 
30
30
  # test for bad subscribers
31
31
  puts "raising..."
32
- assert_raise Rest::HttpError do
32
+ assert_raises Rest::HttpError do
33
33
  # can't subscribe to self
34
34
  res = queue.update_queue(:subscribers => [{:url => "ironmq:///#{publisher_name}"}])
35
35
  end
36
36
 
37
- assert_raise Rest::HttpError do
37
+ assert_raises Rest::HttpError do
38
38
  # must have a token if sending to different project_id
39
39
  res = queue.update_queue(:subscribers => [{:url => "ironmq://ABCDEFG@/somerandomqueue"}])
40
40
  end
@@ -0,0 +1,29 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+ require 'parallel'
5
+ require_relative 'test_base'
6
+
7
+ class TmpTests < TestBase
8
+ def setup
9
+ super
10
+
11
+ end
12
+
13
+ def test_performance_post_100_messages
14
+ queue = @client.queue('test_perf_100')
15
+ # slower to rackspace since this is running on aws
16
+ timeout = @host.include?('rackspace') ? 40 : 12
17
+
18
+ assert_performance(timeout) do
19
+ 100.times do
20
+ queue.post("hello world!")
21
+ end
22
+
23
+ # delete queue on test complete
24
+ resp = queue.delete_queue
25
+ assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
26
+ end
27
+ end
28
+ end
29
+
@@ -14,44 +14,43 @@ class TestPushQueues < TestBase
14
14
 
15
15
  def test_subscriber_add_remove
16
16
  puts "test_subscriber_add_remove"
17
- qname = "subscribers_add_remove_test"
18
- s = "http://nowhere.com:8080/somepath"
19
- s2 = "http://somewhere.com"
17
+ qname = "subscriber_#{Time.now.to_i}"
18
+ first_subscriber = {name: "first_subscriber", url: "http://nowhere.com:8080/somepath"}
19
+ second_subscriber = {name: "second_subscriber", url: "http://somewhere.com"}
20
+ subscribers = [first_subscriber, second_subscriber]
21
+ @client.create_queue(qname, push: {subscribers: subscribers})
20
22
  queue = @client.queue(qname)
21
- subscribers = [{:url => s}]
22
- res = queue.update_queue(:subscribers => subscribers)
23
23
  LOG.debug queue.subscribers
24
- assert_equal 1, queue.subscribers.size
24
+ assert_equal 2, queue.subscribers.size
25
25
 
26
26
  queue.reload
27
- assert_equal 1, queue.subscribers.size
27
+ assert_equal 2, queue.subscribers.size
28
28
  p queue.subscribers[0].url
29
- queue.remove_subscriber({:url => s})
29
+ queue.remove_subscribers([{name: first_subscriber[:name]}])
30
30
  queue.reload
31
- assert_equal 0, queue.subscribers.size
31
+ assert_equal 1, queue.subscribers.size
32
32
  p queue.subscribers
33
33
 
34
34
  # add it back with add
35
- queue.add_subscriber({:url => s})
35
+ queue.add_subscriber(first_subscriber)
36
36
  queue.reload
37
- assert_equal 1, queue.subscribers.size
37
+ assert_equal 2, queue.subscribers.size
38
38
  p queue.subscribers[0].url
39
- queue.remove_subscriber({:url => s})
39
+ queue.remove_subscriber(first_subscriber)
40
40
  queue.reload
41
- assert_equal 0, queue.subscribers.size
41
+ assert_equal 1, queue.subscribers.size
42
42
  p queue.subscribers
43
43
 
44
44
  # add two, remove first
45
- queue.add_subscriber({:url => s})
46
- queue.add_subscriber({:url => s2})
45
+ queue.add_subscriber(first_subscriber)
47
46
  queue.reload
48
47
  assert_equal 2, queue.subscribers.size
49
48
  p queue.subscribers[0].url
50
- queue.remove_subscriber({:url => s})
49
+ queue.remove_subscriber(first_subscriber)
51
50
  queue.reload
52
51
  assert_equal 1, queue.subscribers.size
53
52
  p queue.subscribers[0].url
54
- assert_equal s2, queue.subscribers[0].url
53
+ assert_equal second_subscriber[:url], queue.subscribers[0].url
55
54
 
56
55
  queue.delete_queue
57
56
  end
@@ -66,7 +65,7 @@ class TestPushQueues < TestBase
66
65
 
67
66
  LOG.info "Trying type #{t}"
68
67
 
69
- qname = "subscription-queue-#{t}"
68
+ qname = "subscription-queue-#{Time.now.to_i}"
70
69
  queue_names << qname
71
70
 
72
71
  num_subscribers = 10
@@ -75,22 +74,23 @@ class TestPushQueues < TestBase
75
74
  x = rand(1000)
76
75
  num_subscribers.times do |i|
77
76
  key = make_key(i, t, x)
78
- subscribers << {:url => "http://rest-test.iron.io/code/200?store=#{key}"}
77
+ subscribers << {url: "http://rest-test.iron.io/code/200?store=#{key}",
78
+ name: "name_#{key}"}
79
79
  end
80
80
 
81
+ @client.create_queue(qname, {type: t, push: {subscribers: subscribers}})
81
82
  queue = @client.queue(qname)
82
- res = queue.update_queue(:subscribers => subscribers,
83
- :push_type => t)
84
83
 
85
84
  LOG.debug queue.subscribers
86
85
  assert_equal num_subscribers, queue.subscribers.size
87
86
 
88
87
  # add the last one
89
88
  queue.reload # temporary, can remove
90
- queue.add_subscriber({:url => "http://nowhere.com"})
89
+ subscriber_name = "name_#{Time.now.to_i}"
90
+ queue.add_subscriber({url: "http://nowhere.com", name: subscriber_name})
91
91
  queue.reload
92
92
  assert_equal num_subscribers + 1, queue.subscribers.size
93
- queue.remove_subscriber({:url => "http://nowhere.com"})
93
+ queue.remove_subscriber({name: subscriber_name})
94
94
  queue.reload
95
95
  assert_equal num_subscribers, queue.subscribers.size
96
96
 
@@ -124,7 +124,7 @@ class TestPushQueues < TestBase
124
124
  assert_equal 404, ex.code
125
125
  end
126
126
  end
127
- assert_not_equal tries, 0
127
+ refute_equal tries, 0
128
128
  end
129
129
  elsif t == "unicast"
130
130
  tries = MAX_TRIES
@@ -149,7 +149,7 @@ class TestPushQueues < TestBase
149
149
  end
150
150
  break if found == 1
151
151
  end
152
- assert_not_equal tries, 0
152
+ refute_equal tries, 0
153
153
  end
154
154
 
155
155
  tries = MAX_TRIES
@@ -161,7 +161,7 @@ class TestPushQueues < TestBase
161
161
  sleep 1
162
162
  tries -= 1
163
163
  # old style of message getting
164
- msg = queue.messages.get(m.id)
164
+ msg = queue.messages.get_message(m.id)
165
165
  LOG.info "checking for message: #{msg}"
166
166
  next if msg.nil?
167
167
  subscribers = msg.subscribers
@@ -169,7 +169,7 @@ class TestPushQueues < TestBase
169
169
  LOG.debug subscribers
170
170
  if t == "unicast"
171
171
  assert_equal 1, found
172
- assert_equal 1, subscribers.size
172
+ assert_equal num_subscribers, subscribers.size
173
173
  else # pubsub
174
174
  assert_equal num_subscribers, found
175
175
  assert_equal num_subscribers, subscribers.size
@@ -186,7 +186,7 @@ class TestPushQueues < TestBase
186
186
  next if do_retry
187
187
  break
188
188
  end
189
- assert_not_equal tries, 0
189
+ assert_equal tries, 0
190
190
 
191
191
  # delete queue after all tests on it were completed
192
192
  resp = queue.delete_queue
@@ -196,23 +196,24 @@ class TestPushQueues < TestBase
196
196
 
197
197
  def test_headers
198
198
  puts "test_headers"
199
- qname = "push-headers"
199
+ qname = "push-headers_#{Time.now.to_i}"
200
200
  subscribers = []
201
201
 
202
202
  x = rand(1000)
203
203
  key = "somemsg_#{x}"
204
- subscribers << {:url => "http://rest-test.iron.io/code/200?store=#{key}",
205
- :headers=>{"Content-Type"=>"application/json"}}
204
+ subscribers << {url: "http://rest-test.iron.io/code/200?store=#{key}",
205
+ name: "name_#{key}",
206
+ headers: {"Content-Type"=>"application/json"}}
206
207
 
207
- queue = @client.queue(qname)
208
- queue.update_queue(:subscribers => subscribers,
209
- :push_type => "multicast")
208
+ @client.create_queue(qname, {type: 'multicast',
209
+ push: {subscribers: subscribers}})
210
210
 
211
+ queue = @client.queue(qname)
211
212
  LOG.debug queue.subscribers
212
213
  assert_equal subscribers.size, queue.subscribers.size
213
214
  queue.reload.subscribers.each do |s|
214
215
  p s.headers
215
- assert_not_nil s.headers['Content-Type']
216
+ refute_nil s.headers['Content-Type']
216
217
  end
217
218
 
218
219
  msg = "{\"hello\": #{x}}"
@@ -233,14 +234,14 @@ class TestPushQueues < TestBase
233
234
  parsed = JSON.parse(response.body)
234
235
  LOG.debug parsed['body']
235
236
  assert_equal msg, parsed['body']
236
- assert_not_nil parsed['headers']['Content-Type']
237
+ refute_nil parsed['headers']['Content-Type']
237
238
  assert_equal 'application/json', parsed['headers']['Content-Type']
238
239
  break
239
240
  rescue Rest::HttpError => ex
240
241
  LOG.debug ex.code
241
242
  assert_equal 404, ex.code
242
243
  end
243
- assert_not_equal tries, 0
244
+ refute_equal tries, 0
244
245
  end
245
246
 
246
247
  # delete queue after all tests on it were completed
@@ -251,22 +252,24 @@ class TestPushQueues < TestBase
251
252
 
252
253
  def test_failure
253
254
  @rest = Rest::Client.new
254
- qname = "failure-queue"
255
255
 
256
256
  x = rand(1000)
257
+ qname = "failure-queue_#{x}"
257
258
 
258
259
  subscribers = []
259
- subscribers << {:url => "http://rest-test.iron.io/code/503?switch_after=2&switch_to=200&namespace=push-test-failures-#{x}"}
260
- subscribers << {:url => "http://rest-test.iron.io/code/503"}
260
+ subscribers << {url: "http://rest-test.iron.io/code/503?switch_after=2&switch_to=200&namespace=push-test-failures-#{x}",
261
+ name: "name#{x}"}
262
+ subscribers << {url: "http://rest-test.iron.io/code/503",
263
+ name: "name_#{Time.now.to_i}"}
261
264
 
262
265
  num_subscribers = 2
263
266
 
264
- queue = @client.queue(qname)
265
- res = queue.update_queue(:subscribers => subscribers,
266
- :push_type => "multicast",
267
- :retries => 3,
268
- :retries_delay => 3
269
- )
267
+ @client.create_queue(qname, {type: 'multicast',
268
+ push: {
269
+ subscribers: subscribers,
270
+ retries: 3,
271
+ retries_delay: 3
272
+ }})
270
273
  queue = @client.queue(qname)
271
274
  LOG.debug queue
272
275
  LOG.debug queue.subscribers
@@ -281,7 +284,7 @@ class TestPushQueues < TestBase
281
284
  sleep 0.5
282
285
  tries -= 1
283
286
  LOG.info 'getting status'
284
- subscribers = queue.messages.get(m.id).subscribers
287
+ subscribers = queue.get_message(m.id).subscribers
285
288
  LOG.debug subscribers
286
289
  LOG.info "num_subscribers=#{num_subscribers} subscribers.size=#{subscribers.size}"
287
290
 
@@ -297,14 +300,14 @@ class TestPushQueues < TestBase
297
300
  next if do_retry
298
301
  break
299
302
  end
300
- assert_not_equal tries, 0
303
+ assert_equal tries, 0
301
304
 
302
305
  tries = MAX_TRIES
303
306
  while tries > 0
304
307
  puts 'sleeping for 5 to wait for retry'
305
308
  sleep 5
306
309
  tries -= 1
307
- subscribers = queue.messages.get(m.id).subscribers
310
+ subscribers = queue.get_message(m.id).subscribers
308
311
  LOG.debug subscribers
309
312
  assert_equal num_subscribers, subscribers.size
310
313
  do_retry = false
@@ -330,7 +333,7 @@ class TestPushQueues < TestBase
330
333
  next if do_retry
331
334
  break
332
335
  end
333
- assert_not_equal tries, 0
336
+ assert_equal tries, 0
334
337
 
335
338
  # delete queue on test complete
336
339
  resp = queue.delete_queue
@@ -339,13 +342,13 @@ class TestPushQueues < TestBase
339
342
 
340
343
 
341
344
  def test_202
342
- puts "test_202"
345
+ puts "test_202_#{Time.now.to_i}"
343
346
  types = ["multicast"]
344
347
  types.each do |t|
345
348
 
346
349
  LOG.info "Trying type #{t}"
347
350
 
348
- qname = "subscription-queue-#{t}-202"
351
+ qname = "subscription-queue-#{Time.now.to_i}"
349
352
 
350
353
  num_subscribers = 2
351
354
  subscribers = []
@@ -353,20 +356,20 @@ class TestPushQueues < TestBase
353
356
  x = rand(1000)
354
357
  num_subscribers.times do |i|
355
358
  key = make_key(i, t, x)
356
- subscribers << {:url => "http://rest-test.iron.io/code/202?store=#{key}"}
359
+ subscribers << {url: "http://test.iron.io/code/202?store=#{key}", name: "name_#{key}"}
357
360
  end
358
361
 
362
+ res = @client.create_queue(qname, {type: t,
363
+ push: {subscribers: subscribers}})
359
364
  queue = @client.queue(qname)
360
- res = queue.update_queue(:subscribers => subscribers,
361
- :push_type => t)
362
365
 
363
366
  queue.reload
364
367
  LOG.debug queue
365
368
  queue = @client.queue(qname)
366
369
 
367
370
  assert_equal num_subscribers, queue.subscribers.size
368
- assert_equal t, queue.push_type
369
- puts "queue.push_type: #{queue.push_type}"
371
+ assert_equal t, queue.type
372
+ puts "queue.push_type: #{queue.type}"
370
373
  # todo: assert subscriptions match
371
374
 
372
375
  msg = "hello #{x}"
@@ -376,7 +379,7 @@ class TestPushQueues < TestBase
376
379
  while tries > 0
377
380
  sleep 0.5
378
381
  tries -= 1
379
- subscribers = queue.messages.get(m.id).subscribers
382
+ subscribers = queue.get_message(m.id).subscribers
380
383
  LOG.debug subscribers
381
384
  assert_equal num_subscribers, subscribers.size
382
385
  do_retry = false
@@ -388,7 +391,7 @@ class TestPushQueues < TestBase
388
391
  next if do_retry
389
392
  break
390
393
  end
391
- assert_not_equal tries, 0
394
+ assert_equal tries, 0
392
395
 
393
396
  LOG.info 'sleeping 2'
394
397
  sleep 2
@@ -396,10 +399,10 @@ class TestPushQueues < TestBase
396
399
  tries = MAX_TRIES
397
400
  while tries > 0
398
401
  sleep 0.5
399
- subscribers = queue.messages.get(m.id).subscribers
402
+ subscribers = queue.get_message(m.id).subscribers
400
403
  LOG.debug subscribers
401
404
  assert_equal num_subscribers, subscribers.size
402
- assert_equal t, queue.push_type
405
+ assert_equal t, queue.type
403
406
 
404
407
  do_retry = false
405
408
  subscribers.each do |s|
@@ -423,13 +426,13 @@ class TestPushQueues < TestBase
423
426
  end
424
427
  break
425
428
  end
426
- assert_not_equal 0, tries
429
+ refute_equal 0, tries
427
430
 
428
431
  tries = MAX_TRIES
429
432
  while tries > 0
430
433
  sleep 0.5
431
434
  tries -= 1
432
- subscribers = queue.messages.get(m.id).subscribers
435
+ subscribers = queue.get_message(m.id).subscribers
433
436
  LOG.debug subscribers
434
437
  next unless num_subscribers == subscribers.size
435
438
 
@@ -442,7 +445,7 @@ class TestPushQueues < TestBase
442
445
  next if do_retry
443
446
  break
444
447
  end
445
- assert_not_equal 0, tries
448
+ refute_equal 0, tries
446
449
 
447
450
  # delete queue on test complete
448
451
  resp = queue.delete_queue
@@ -451,14 +454,15 @@ class TestPushQueues < TestBase
451
454
  end
452
455
 
453
456
  def test_post_and_instantiate
454
- queue = @client.queue('push_and_instantiate')
457
+ qname = "push_and_instantiate#{Time.now.to_i}"
455
458
 
456
- subscribers = [{:url => "http://rest-test.iron.io/code/200"},
457
- {:url => "http://rest-test.iron.io/code/200"}]
459
+ subscribers = [{:url => "http://rest-test.iron.io/code/200", name: "name#{Time.now.to_i}"},
460
+ {:url => "http://rest-test.iron.io/code/200",name: "name#{Time.now.to_i}"}]
458
461
 
459
- res = queue.update_queue(:subscribers => subscribers,
460
- :push_type => 'multicast')
462
+ res = @client.create_queue(qname, {type: 'multicast',
463
+ push: {subscribers: subscribers}})
461
464
 
465
+ queue = @client.queue(qname)
462
466
  expected_size = subscribers.size
463
467
  got_size = queue.subscribers.size
464
468
  assert_equal expected_size, got_size, "queue's subscribers list must contain #{expected_size} elements, but got #{got_size}"
@@ -470,45 +474,13 @@ class TestPushQueues < TestBase
470
474
 
471
475
  sleep 5
472
476
 
473
- msgs.each do |msg|
474
- subscr_arr = msg.subscribers
475
- subscr_arr.each do |s|
476
- assert_instance_of(IronMQ::Subscriber, s, "message must return `Subscriber`, but got `#{s.class}`")
477
- rsp = s.delete
478
- assert_equal 200, rsp.code, "API must response with HTTP 200 status, but returned HTTP #{rsp.code}"
479
- end
480
- end
481
-
482
477
  resp = queue.delete_queue
483
478
  assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
484
479
  end
485
480
 
486
-
487
- # tests when converting a push queue back to a pull queue
488
- def test_converting_types
489
- queue = @client.queue('converting_queue')
490
- subscribers = [{:url => "http://rest-test.iron.io/code/200"},
491
- {:url => "http://rest-test.iron.io/code/200"}]
492
-
493
- res = queue.update_queue(:subscribers => subscribers,
494
- :push_type => 'multicast')
495
- queue.reload
496
-
497
- assert_equal "multicast", queue.push_type
498
-
499
- p queue.update_queue(:push_type => 'pull')
500
-
501
- queue.reload
502
-
503
- p queue.push_type
504
-
505
- assert_nil queue.push_type
506
-
507
- end
508
-
509
481
  def test_error_queues
510
482
  @rest = Rest::Client.new
511
- qname = "badrobot"
483
+ qname = "badrobot#{Time.now.to_i}"
512
484
  error_queue_name = "#{qname}--errors"
513
485
  clear_queue(qname)
514
486
  clear_queue(error_queue_name)
@@ -516,18 +488,17 @@ class TestPushQueues < TestBase
516
488
  x = rand(1000)
517
489
 
518
490
  subscribers = []
519
- subscribers << {:url => "http://rest-test.iron.io/code/503"}
491
+ subscribers << {:url => "http://rest-test.iron.io/code/503", name: "name_#{Time.now.to_i}"}
520
492
  subscriber_urls = subscribers
521
493
  num_subscribers = subscribers.size
522
494
 
495
+ res = @client.create_queue(qname, push: {
496
+ subscribers: subscribers,
497
+ retries: 3,
498
+ retries_delay: 3,
499
+ error_queue: error_queue_name
500
+ })
523
501
  queue = @client.queue(qname)
524
- res = queue.update_queue(:subscribers => subscribers,
525
- :push_type => "multicast",
526
- :retries => 3,
527
- :retries_delay => 3
528
- )
529
- res = queue.update_queue(:error_queue => error_queue_name)
530
-
531
502
  msg = "hello #{x}"
532
503
  puts "Pushing msg: #{msg}"
533
504
  m = queue.post(msg)
@@ -540,7 +511,7 @@ class TestPushQueues < TestBase
540
511
  puts 'sleeping for 5 to wait for retry'
541
512
  sleep 5
542
513
  tries -= 1
543
- subscribers = queue.messages.get(m.id).subscribers
514
+ subscribers = queue.get_message(m.id).subscribers
544
515
  LOG.debug subscribers
545
516
  assert_equal num_subscribers, subscribers.size
546
517
  do_retry = false
@@ -566,20 +537,18 @@ class TestPushQueues < TestBase
566
537
  next if do_retry
567
538
  break
568
539
  end
569
- assert_not_equal tries, 0
570
540
 
571
541
  # check that the failed messages is in the error queue
572
542
  error_queue = @client.queue(error_queue_name)
573
543
  em = error_queue.get
574
- assert_not_nil em
544
+ refute_nil em
575
545
  puts "rawbody: " + em.body
576
546
  error_hash = JSON.parse(em.body)
577
- p error_hash
578
547
  assert error_hash['subscribers']
579
548
  assert_equal subscriber_urls[0][:url], error_hash['subscribers'][0]['url']
580
- assert_equal 503, error_hash['code']
549
+ assert_equal 503, error_hash['subscribers'][0]['code']
581
550
  assert_equal orig_id, error_hash['source_msg_id']
582
- assert_not_nil error_hash['msg']
551
+ refute_nil error_hash['subscribers'][0]['msg']
583
552
  em.delete
584
553
 
585
554
  # now let's get the original message