程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 rspec-sidekiq 测试 sidekiq 工作器不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 rspec-sidekiq 测试 sidekiq 工作器不起作用?

开发过程中遇到使用 rspec-sidekiq 测试 sidekiq 工作器不起作用的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 rspec-sidekiq 测试 sidekiq 工作器不起作用的解决方法建议,希望对你解决使用 rspec-sidekiq 测试 sidekiq 工作器不起作用有所启发或帮助;

这是我的测试代码:

require 'rails_Helper'

describe CookcookieWorker do
  let(:user) { FactoryGirl.create(:user) }
  let(:oven) { user.ovens.first }

  it { is_expected.to be_processed_in :cookies }

  it 'enqueues the cook cookies worker to be processed in 5 seconds' do
    oven.cookies.create!({ fillings: 'Vanilla' })
    cookie = oven.cookies.last

    expect(CookcookieWorker).to have_enqueued_sIDekiq_job(cookie.ID).in(5.seconds)
  end
end

这是我得到的结果

expected to have an enqueued CookcookieWorker job
         arguments: [1]
         options: {"in"=>5 seconds}
       found
         arguments: []
         options: []

澄清一下,我在 after_save 模型中有一个 cookie 回调,它以这种方式调用工作线程:

CookcookieWorker.perform_in(5.seconds,ID)

一开始我想可能我无法通过这种方式测试工作人员,可能是模型回调没有效果?但是我尝试在测试中手动调用工作人员:

require 'rails_Helper'

describe CookcookieWorker do
  let(:user) { FactoryGirl.create(:user) }
  let(:oven) { user.ovens.first }

  it { is_expected.to be_processed_in :cookies }

  it 'enqueues the cook cookies worker to be processed in 5 seconds' do
    oven.cookies.create!({ fillings: 'Vanilla' })
    cookie = oven.cookies.last

    CookcookieWorker.perform_in(5.seconds,cookie.ID) # Calling it manually
    expect(CookcookieWorker).to have_enqueued_sIDekiq_job(cookie.ID).in(5.seconds)
  end
end

但我得到相同的结果,测试失败。有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的使用 rspec-sidekiq 测试 sidekiq 工作器不起作用全部内容,希望文章能够帮你解决使用 rspec-sidekiq 测试 sidekiq 工作器不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。