Sha256: 08873ca4211a814b883fae4a4e7bc02cca4be9d1279aee23962bac2619a13b38

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class ResqueTest < Test::Unit::TestCase

  context "Resque" do
    setup do
      Resque.redis.flush_all
      assert_nil Resque.redis.get(OneHourThrottledJob.key)
      @bogus_args = "bogus_arg"
    end

    context "#enqueue" do
      should "add a throttled job key to the set with the proper TTL (Expire)" do
        Resque.expects(:enqueue_without_throttle).returns(true) 
        assert Resque.enqueue(IdentifierThrottledJob, @bogus_args)
        assert Resque.redis.keys('*').include?("resque:IdentifierThrottledJob:my_bogus_arg")
        assert_equal 3600, Resque.redis.ttl(IdentifierThrottledJob.key(@bogus_args))
      end
      
      context "job has not reached throttle limit" do
        should "not add another job to the queue and raise a throttled exception" do
          Resque.expects(:enqueue_without_throttle).once
          assert_raises(Resque::ThrottledError) { 2.times { Resque.enqueue(OneHourThrottledJob, @bogus_args) } }
        end
      end

      should "enqueue a job without throttling if the job is disabled" do
        Resque.expects(:enqueue_without_throttle).twice
        2.times { Resque.enqueue(DisabledThrottledJob, @bogus_args) }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
tech-angels-resque-throttle-0.2.20 test/resque/resque_test.rb
resque-throttle-0.2.19 test/resque/resque_test.rb
resque-throttle-0.2.18 test/resque/resque_test.rb
resque-throttle-0.2.17 test/resque/resque_test.rb
resque-throttle-0.2.16 test/resque/resque_test.rb
resque-throttle-0.2.15 test/resque/resque_test.rb
resque-throttle-0.2.14 test/resque/resque_test.rb
resque-throttle-0.2.13 test/resque/resque_test.rb
resque-throttle-0.2.12 test/resque/resque_test.rb
resque-throttle-0.2.11 test/resque/resque_test.rb
resque-throttle-0.2.10 test/resque/resque_test.rb