Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 67 lines (49 sloc) 1.434 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
require 'rubygems'
require 'test/unit'
require 'yaml'
require 'uber_config'

begin
  require File.expand_path('../lib/iron_mq', File.dirname(__FILE__))
rescue Exception => ex
  puts "Could NOT load current iron_mq: " + ex.message
  raise ex
end

LOG = Logger.new(STDOUT)
LOG.level = Logger::INFO
MAX_TRIES = 10

class TestBase < Test::Unit::TestCase

  def setup
    puts 'setup'
    # check multiple config locations
    @config = UberConfig.load
    puts "config=" + @config.inspect

    config = @config['iron']
    @host = "#{config['host'] || "mq-aws-us-east-1.iron.io"}"

    @client = IronMQ::Client.new(@config['iron'])
    puts "IronMQ::VERSION = #{IronMQ::VERSION}"
    #Rest.logger.level = Logger::DEBUG # this doesn't work for some reason?
    #IronCore::Logger.logger.level = Logger::DEBUG

    @queue_name = 'ironmq-ruby-tests' # default queue for tests
  end


  def clear_queue(queue_name=nil)
    queue_name ||= @queue_name

    queue = @client.queue(queue_name)

    puts "clearing queue #{queue_name}"
    begin
      queue.clear
      puts 'cleared.'
    rescue Rest::HttpError => ex
      if ex.code == 404
        # this is fine
      else
        raise ex
      end
    end

  end

  def assert_performance(time)
    start_time = Time.now

    yield

    execution_time = Time.now - start_time

    assert execution_time < time, "Execution time too big #{execution_time.round(2)}, should be #{time}"
  end

end
Something went wrong with that request. Please try again.