RSPEC:如何测试具有Sidekiq_option lock的工人::直至dex_exected Isn' t in两次?

发布于 2025-01-30 08:17:16 字数 707 浏览 1 评论 0 原文

我想用rspec和gem

假设我有这项工作:

class TestJob < ApplicationWorker
  include Sidekiq::Worker

  sidekiq_options queue: 'test_queue', lock: :until_executed

  def perform
    puts "Hello World !"
  end
end

我希望能够通过以下测试进行测试:

it "doesn't enqueue a job to send an email to the rider" do
  TestJob.perform_async
  TestJob.perform_async
  expect(TestJob.jobs.size).to eq(1)
end

这将使我确定我的工作永远不会排队不止一次。

你怎么做?

I'd like to test my worker with Rspec and the gem sidekiq-uniq-job.

Let's say I have this job :

class TestJob < ApplicationWorker
  include Sidekiq::Worker

  sidekiq_options queue: 'test_queue', lock: :until_executed

  def perform
    puts "Hello World !"
  end
end

I would like to be able to test it with the following test for instance :

it "doesn't enqueue a job to send an email to the rider" do
  TestJob.perform_async
  TestJob.perform_async
  expect(TestJob.jobs.size).to eq(1)
end

This would allow me to be sure that my job will never be queued more than once.

How would you do it ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文