Sha256: 5594a5d159938406f3463efbbc884c60132e8d027e8c72855c0956e8c0815580

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'helper'
require 'jobs/logging_job'
require 'active_support/core_ext/numeric/time'

class LockQueuingTest < ActiveSupport::TestCase

  setup do
    TestJob.lock_with do |arg|
      "#{@id}-#{arg % 4}"
    end
  end

  test 'should run jobs enqueued on a listening queue' do
    TestJob.perform_later @id
    wait_for_jobs_to_finish_for(5.seconds)
    assert job_executed
  end

  test 'should not run job if another one with same lock enqueued' do
    TestJob.perform_later 0
    TestJob.perform_later 4
    wait_for_jobs_to_finish_for(5.seconds, 0)
    wait_for_jobs_to_finish_for(5.seconds, 4)
    refute job_executed(4)
    assert job_executed(0)
  end

  test 'should run job if another one with different lock enqueued' do
    TestJob.perform_later 1
    TestJob.perform_later 2
    wait_for_jobs_to_finish_for(5.seconds, 2)
    assert job_executed(2)
    assert job_executed(1)
  end

  test 'should run job if another one with same lock and different class enqueued' do
    TestJob2.perform_later 7
    TestJob.perform_later 3
    wait_for_jobs_to_finish_for(5.seconds, 3)
    assert job_executed(3)
    assert job_executed(7)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 test/integration/lock_queuing_test.rb
activejob-lock-0.0.1 test/integration/lock_queuing_test.rb