Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniqueness should not survive Class.jobs.clear #214

Closed
nbdavies opened this issue Apr 13, 2017 · 3 comments
Closed

Uniqueness should not survive Class.jobs.clear #214

nbdavies opened this issue Apr 13, 2017 · 3 comments

Comments

@nbdavies
Copy link

nbdavies commented Apr 13, 2017

This is probably easiest to demonstrate with a failing test:

  test 'sidekiq_uniqueness after clearing jobs' do
    MyWorker.jobs.clear
    assert_equal 0, MyWorker.jobs.size
    MyWorker.perform_async
    assert_equal 1, MyWorker.jobs.size
    MyWorker.jobs.clear
    assert_equal 0, MyWorker.jobs.size
    MyWorker.perform_async
    assert_equal 1, MyWorker.jobs.size
  end

To break this down:

  1. Any jobs for class MyWorker are removed from the queue. There are now 0 jobs in the queue.
  2. I enqueue a job for class MyWorker. Now there's one job in the queue for that class.
  3. I clear the jobs again so I can test another assertion. There are now 0 jobs in the queue.
  4. I enqueue another job with the same class/parameters as in step 2. I would expect the queue to now have 1 job in it, because the previous job got cleared away.

MyWorker is unique until_executed. But with MyClass.jobs.clear, it's removed from the queue without being executed. It seems like the subsequent job is not being enqueued because it's a duplicate (not unique) relative to the one that got cleared away.

My assumption would be that, if you wanted to simulate the previous job being executed, you would use MyClass.drain. So if you're using MyClass.jobs.clear, which doesn't perform the job at all, and doesn't satisfy the until_executed condition, you're resetting the queue, and it should act as if the previous job was never there.

@mhenrixon
Copy link
Owner

Did you require sidekiq_unique_jobs/testing?

@mhenrixon
Copy link
Owner

I think you are supposed to use Sidekiq::Worker.clear_all or UntilExecutedJob.drain. See the following file for some more suggestions https://github.com/mhenrixon/sidekiq-unique-jobs/blame/master/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb#L1

@mhenrixon
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants