Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add basic beanstalk tests

  • Loading branch information...
commit 1fd986d6c9d5552da99b83d0a5280ed516ac9c93 1 parent 7e81fa4
@edsrzf edsrzf authored
Showing with 33 additions and 3 deletions.
  1. +33 −3 test/test_iron_mq.rb
View
36 test/test_iron_mq.rb
@@ -4,6 +4,7 @@
gem 'test-unit'
require 'test/unit'
+require 'beanstalk-client'
require 'yaml'
require_relative 'test_base'
@@ -15,7 +16,6 @@ def setup
end
-
def test_basics
@client.queue_name = 'test_basics'
clear_queue
@@ -155,9 +155,39 @@ def test_batch
msgs.each do |m|
m.delete
end
-
-
end
+ def test_beanstalk
+ puts 'test_beanstalk'
+ config = @config['iron_mq']
+ h = "#{config['host']}:#{config['beanstalkd_port']||11300}"
+ beanstalk = Beanstalk::Connection.new(h)
+ beanstalk.put("oauth #{config['token']} #{config['project_id']}")
+ beanstalk.use(@client.queue_name)
+ beanstalk.watch(@client.queue_name)
+
+ msg = "hello #{Time.now}"
+ beanstalk.put(msg)
+ job = beanstalk.reserve
+ assert_equal msg, job.body, "body not the same as message."
+ job.delete
+ job = assert_raise(Beanstalk::TimedOut) {
+ beanstalk.reserve(1)
+ }
+
+ hasher = {:x=>1, :y=>"hello", "yo"=>"scooby doo"}
+ beanstalk.put(hasher.to_json)
+ job = beanstalk.reserve(1)
+ got = JSON.parse(job.body)
+ assert got.is_a?(Hash)
+ assert_equal hasher[:x], got['x']
+ job.delete
+
+ msg = "hello there\nthis is a new line"
+ beanstalk.put(msg)
+ job = beanstalk.reserve(1)
+ assert_equal msg, job.body, "#{job.body} does not equal #{msg}"
+ job.delete
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.