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

Add "immediately" matcher #210

Merged
merged 3 commits into from
Sep 12, 2023

Conversation

chrismaximin
Copy link
Contributor

@chrismaximin chrismaximin commented Sep 10, 2023

The issue

There is currently no way to check whether a job was scheduled for some point in the future, or enqueued immediately.
Specifically, we can't use have_enqueued_sidekiq_job.at( ... ) if a job was enqueued immediately.

This is because when Sidekiq doesn't add a "at" option when the date was in the past, which rspec-sidekiq currently relies on:
https://github.com/sidekiq/sidekiq/blob/bd1ca2b94ad73abdfd4347c83be527bb3ff60acb/lib/sidekiq/job.rb#L328C1-L329

This PR

This PR enables this:

# MyJob will enqueued immediately by Sidekiq, not scheduled.
# It is equivalent to writing `MyJob.perform_async("hello")`
MyJob.perform_at(5.seconds.ago, "hello")

expect(MyJob).to have_enqueued_sidekiq_job("hello").immediately # passes

@wspurgin
Copy link
Owner

Thanks @chrismaximin Could you clarify the first statement though?

There is currently no way to check whether a job was scheduled for some point in the future or enqueued immediately.

This statement, on first read, is not true. You can absolutely test that something was enqueued for the future...

I'm not against adding an explicit "no wait" option to the matcher - in other words testing, explicitly, that no delay was specified when enqueuing.

Could you add specs to enqueue_sidekiq_job_spec as well? If you wanna add some docs to both matchers, I'd be much obliged 👍

@chrismaximin
Copy link
Contributor Author

There is currently no way to check whether a job was scheduled for some point in the future or enqueued immediately.

This statement, on first read, is not true. You can absolutely test that something was enqueued for the future...

The statement was too broad indeed. I meant "There is currently no way to check in a whether a job was scheduled or enqueued".
I added docs in the README and in matchers/enqueue_sidekiq_job.rb for YARD, the other places being private.

Copy link
Owner

@wspurgin wspurgin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition Chris!

@@ -177,6 +177,26 @@
end
end

context "immediately" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻 Great!

#
# # Without any delay
# expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job.immediately
# expect { AwesomeJob.perform_at(1.hour.ago) }.to enqueue_sidekiq_job.immediately
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇 Thanks for adding the docs too.

@wspurgin wspurgin merged commit 2cc9973 into wspurgin:main Sep 12, 2023
28 checks passed
@wspurgin
Copy link
Owner

I have a couple things to add for a 4.1 (composable support for example), that this will be included in. Thanks again for the contribution @chrismaximin

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

Successfully merging this pull request may close these issues.

2 participants