Skip to content

Commit

Permalink
Add basic beanstalk tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Shaw committed Jan 16, 2012
1 parent 7e81fa4 commit 1fd986d
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions test/test_iron_mq.rb
Expand Up @@ -4,6 +4,7 @@

gem 'test-unit'
require 'test/unit'
require 'beanstalk-client'
require 'yaml'
require_relative 'test_base'

Expand All @@ -15,7 +16,6 @@ def setup

end


def test_basics
@client.queue_name = 'test_basics'
clear_queue
Expand Down Expand Up @@ -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

0 comments on commit 1fd986d

Please sign in to comment.