Permalink
Browse files

Adeed custom header tests.

  • Loading branch information...
1 parent 73bcf82 commit 1a0fc2323b5a526a29ef626e4fab3a2756623c2a @treeder treeder committed Dec 20, 2013
Showing with 81 additions and 18 deletions.
  1. +7 −7 Gemfile.lock
  2. +8 −0 lib/iron_mq/subscribers.rb
  3. +66 −11 test/test_push_queues.rb
View
@@ -12,17 +12,17 @@ GEM
ethon (0.6.1)
ffi (>= 1.3.0)
mime-types (~> 1.18)
- ffi (1.9.0)
+ ffi (1.9.3)
go (1.1.0)
concur
iron_core (1.0.1)
rest (>= 2.2.0)
- iron_worker_ng (1.0.2)
- bundler (>= 1.2.0)
+ iron_worker_ng (1.0.4)
+ bundler
iron_core (>= 1.0.0)
rubyzip (= 0.9.9)
- mime-types (1.25)
- minitest (5.0.8)
+ mime-types (1.25.1)
+ minitest (5.1.0)
net-http-persistent (2.9)
quicky (0.4.0)
rake (10.1.0)
@@ -33,9 +33,9 @@ GEM
mime-types (>= 1.16)
rubyzip (0.9.9)
test-unit (2.5.5)
- typhoeus (0.6.5)
+ typhoeus (0.6.6)
ethon (~> 0.6.1)
- uber_config (1.0.5)
+ uber_config (1.1.0)
PLATFORMS
ruby
@@ -10,6 +10,14 @@ def initialize(data, message, options = {})
@options = options
end
+ def url
+ @raw['url']
+ end
+
+ def headers
+ @raw['headers']
+ end
+
# `options` was kept for backward compatibility
def delete(options = {})
@message.call_api_and_parse_response(:delete, path)
@@ -69,6 +69,7 @@ def test_queue_subscriptions
url = "http://rest-test.iron.io/stored/#{key}"
LOG.info "checking url #{url}"
response = @rest.get(url)
+ p response.body
parsed = JSON.parse(response.body)
LOG.debug parsed['body']
assert_equal msg, parsed['body']
@@ -78,7 +79,7 @@ def test_queue_subscriptions
LOG.debug ex.code
assert_equal 404, ex.code
end
- end
+ end
assert_not_equal tries, 0
end
elsif t == "unicast"
@@ -103,15 +104,15 @@ def test_queue_subscriptions
end
end
break if found == 1
- end
+ end
assert_not_equal tries, 0
end
tries = MAX_TRIES
while tries > 0
# Need to wait > 60s here, because in case of retries on pusherd
- # side (due lost connection for example) there will be no response earlier
+ # side (due lost connection for example) there will be no response earlier
# (default retries_delay is 60s).
sleep 1
tries -= 1
@@ -149,6 +150,60 @@ def test_queue_subscriptions
end
end
+ def test_headers
+ puts "test_headers"
+ qname = "push-headers"
+ subscribers = []
+
+ x = rand(1000)
+ key = "somemsg_#{x}"
+ subscribers << {:url => "http://rest-test.iron.io/code/200?store=#{key}",
+ :headers=>{"Content-Type"=>"application/json"}}
+
+ queue = @client.queue(qname)
+ queue.update_queue(:subscribers => subscribers,
+ :push_type => "multicast")
+
+ LOG.debug queue.subscribers
+ assert_equal subscribers.size, queue.subscribers.size
+ queue.reload.subscribers.each do |s|
+ p s.headers
+ assert_not_nil s.headers['Content-Type']
+ end
+
+ msg = "{\"hello\": #{x}}"
+ m = queue.post(msg)
+
+ LOG.info "Checking results..."
+ @rest = Rest::Client.new
+ found = 0
+ tries = MAX_TRIES
+ while tries > 0
+ tries -= 1
+ sleep 1
+ begin
+ url = "http://rest-test.iron.io/stored/#{key}"
+ LOG.info "checking url #{url}"
+ response = @rest.get(url)
+ p response.body
+ parsed = JSON.parse(response.body)
+ LOG.debug parsed['body']
+ assert_equal msg, parsed['body']
+ assert_not_nil parsed['headers']['Content-Type']
+ assert_equal 'application/json', parsed['headers']['Content-Type']
+ break
+ rescue Rest::HttpError => ex
+ LOG.debug ex.code
+ assert_equal 404, ex.code
+ end
+ assert_not_equal tries, 0
+ end
+
+ # delete queue after all tests on it were completed
+ resp = queue.delete_queue
+ assert_equal 200, resp.code, "API must respond with HTTP 200 status, but returned HTTP #{resp.code}"
+ end
+
def test_failure
@rest = Rest::Client.new
@@ -176,7 +231,7 @@ def test_failure
msg = "hello #{x}"
m = queue.post(msg)
LOG.debug m
-
+
tries = MAX_TRIES
while tries > 0
sleep 0.5
@@ -333,7 +388,7 @@ def test_202
subscribers = queue.messages.get(m.id).subscribers
LOG.debug subscribers
next unless num_subscribers == subscribers.size
-
+
do_retry = false
subscribers.each do |s|
LOG.debug s
@@ -385,7 +440,7 @@ def test_post_and_instantiate
end
- # tests when converting a push queue back to a pull queue
+# tests when converting a push queue back to a pull queue
def test_converting_types
queue = @client.queue('converting_queue')
subscribers = [{:url => "http://rest-test.iron.io/code/200"},
@@ -406,7 +461,7 @@ def test_converting_types
assert_nil queue.push_type
end
-
+
def test_error_queues
@rest = Rest::Client.new
qname = "badrobot"
@@ -435,7 +490,7 @@ def test_error_queues
orig_id = m.id
puts "Msg id on post: #{orig_id}"
LOG.debug m
-
+
tries = MAX_TRIES
while tries > 0
puts 'sleeping for 5 to wait for retry'
@@ -468,7 +523,7 @@ def test_error_queues
break
end
assert_not_equal tries, 0
-
+
# check that the failed messages is in the error queue
error_queue = @client.queue(error_queue_name)
em = error_queue.get
@@ -482,14 +537,14 @@ def test_error_queues
assert_equal orig_id, error_hash['source_msg_id']
assert_not_nil error_hash['msg']
em.delete
-
+
# now let's get the original message
orig_msg = queue.get_message(error_hash['source_msg_id'])
puts "orig_msg:"
p orig_msg
p orig_msg.body
assert msg, orig_msg.body
-
+
error_queue.delete_queue
# delete queue on test complete
resp = queue.delete_queue

0 comments on commit 1a0fc23

Please sign in to comment.