Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests for push queues.

  • Loading branch information...
commit 4361cf50bf1f30c81e0be9c36f2867e36f579208 1 parent addb014
@treeder treeder authored
View
10 Gemfile.lock
@@ -11,9 +11,12 @@ GEM
concur (1.0.0)
faraday
faraday
+ ethon (0.5.2)
+ ffi (~> 1.0.11)
+ mime-types (~> 1.18)
faraday (0.8.4)
multipart-post (~> 1.1)
- ffi (1.1.5)
+ ffi (1.0.11)
iron_core (0.4.3)
rest (>= 2.0.2)
mime-types (1.19)
@@ -27,9 +30,8 @@ GEM
rest-client (1.6.7)
mime-types (>= 1.16)
test-unit (2.5.2)
- typhoeus (0.4.2)
- ffi (~> 1.0)
- mime-types (~> 1.18)
+ typhoeus (0.5.0)
+ ethon (= 0.5.2)
uber_config (1.0.5)
PLATFORMS
View
13 lib/iron_mq/queues.rb
@@ -61,7 +61,6 @@ def post(options={})
res = @client.parse_response(@client.post(path(options), options))
res
p res
-
end
@@ -94,6 +93,10 @@ def reload
load_queue
end
+ def subscriptions
+ raw["subscriptions"]
+ end
+
# Used if lazy loading
def load_queue
q = @client.queues.get(:name => name)
@@ -163,6 +166,14 @@ def delete(id, options={})
@client.messages.delete(id, options.merge(:queue_name => name))
end
+ # updates the Queue object itself
+ def update(options)
+ @client.queues.post(options.merge(:name=>name))
+ end
+
+ def delete!(options={})
+ @client.queues.delete(options.merge(:name=>name))
+ end
end
end
View
72 test/quick_run.rb
@@ -1,5 +1,7 @@
require_relative 'test_base'
+TIMES = 100
+
class QuickRun < TestBase
def setup
@@ -10,39 +12,43 @@ def setup
def test_basics
- res = @client.messages.post("hello world!")
- p res
- assert res.id
- post_id = res.id
- assert res.msg
-
- res = @client.messages.get()
- p res
- puts "post_id=" + post_id.inspect
- assert res.id
- assert_equal res.id, post_id
- assert res.body
-
- res = @client.messages.delete(res["id"])
- p res
- assert res.msg
-
- res = @client.messages.get()
- p res
- assert res.nil?
-
- res = @client.messages.post("hello world!", :queue_name=>'test2')
- p res
- assert res.id
- assert res.msg
-
- res = @client.messages.get(:queue_name=>'test2')
- p res
- assert res.id
- assert res.body
-
- res = res.delete
- p res
+ TIMES.times do |i|
+ puts "Loop #{i}"
+
+ res = @client.messages.post("hello world!")
+ p res
+ assert res.id
+ post_id = res.id
+ assert res.msg
+
+ res = @client.messages.get()
+ p res
+ puts "post_id=" + post_id.inspect
+ assert res.id
+ assert_equal res.id, post_id
+ assert res.body
+
+ res = @client.messages.delete(res["id"])
+ p res
+ assert res.msg
+
+ res = @client.messages.get()
+ p res
+ assert res.nil?
+
+ res = @client.messages.post("hello world!", :queue_name => 'test2')
+ p res
+ assert res.id
+ assert res.msg
+
+ res = @client.messages.get(:queue_name => 'test2')
+ p res
+ assert res.id
+ assert res.body
+
+ res = res.delete
+ p res
+ end
end
View
53 test/test_push_queues.rb
@@ -5,26 +5,51 @@ class TestPushQueues < TestBase
def setup
super
- @client.queue_name = 'ironmq-gem-quick'
end
- def test_message_subscriptions
- res = @client.messages.post("hello world!", :subscriptions=>["http://requestb.in/oui4adou"])
- assert res.id
- post_id = res.id
- assert res.msg
- p res
- end
+ #def test_message_subscriptions
+ # res = @client.messages.post("hello world!", :subscriptions=>["http://requestb.in/oui4adou"])
+ # assert res.id
+ # post_id = res.id
+ # assert res.msg
+ # p res
+ #end
def test_queue_subscriptions
qname = "subscription-queue"
- res = @client.queues.post(:queue_name=>qname, :subscriptions=>["http://requestb.in/1lhkwk31", "http://requestb.in/1icckwe1"])
- q = @client.queues.get(:queue_name=>qname)
- p q
- p q["subscriptions"]
-
- @client.messages.post("hello sub queue", :queue_name=>qname)
+ num_subscribers = 2
+ subscribers = []
+ num_subscribers.times do |i|
+ subscribers << "http://rest-test.iron.io/code/200?store=pushq#{i}"
+ end
+
+ queue = @client.queue(qname)
+ res = queue.update(:subscriptions => subscribers,
+ :push_type => "pubsub")
+ queue = @client.queue(qname)
+ p queue
+ p queue.subscriptions
+
+ x = rand(1000)
+ msg = "hello #{x}"
+ queue.post(msg)
+
+ puts "sleeping..."
+ sleep 5
+ puts "Checking results..."
+ @rest = Rest::Client.new
+ num_subscribers.times do |i|
+ begin
+ response = @rest.get("http://rest-test.iron.io/stored/pushq#{i}")
+ parsed = JSON.parse(response.body)
+ p parsed
+ assert_equal msg, parsed['body']
+ rescue Rest::HttpError => ex
+ p ex.code
+ end
+ end
+ # assert_equal msg, post_body
end
Please sign in to comment.
Something went wrong with that request. Please try again.