我的Sidekiq工作人员如下例所示:
Class BooksWorker
include Sidekiq::Worker
def perform
books = Book.where(collected: true)
books.each do |book|
book.update_attribute(:status, "read")
book.toggle!(:collected)
end
end
end
我想在禁用模式下使用Sidekiq测试来检查:
我可以创建哪种测试来检查上述所有四点?
考虑下面的示例测试:
require 'test_helper'
require 'sidekiq/testing'
class BooksWorkerDisableTest < Minitest::Test
def setup
configure = -> (config) do
config.redis = { url: 'redis://localhost:6379/15' }
end
Sidekiq.configure_client(&configure)
Sidekiq.configure_server(&configure)
Sidekiq::Testing.disable!
@books = Book.where(collected: true)
end
test "collected books should be marked as read before archived" do
BooksWorker.perform_async
@books.each do |book|
assert book.status == "read"
assert book.collected == false
end
end
end
如果测试期间Sidekiq将作业排队,请推送到Redis,从Redis检索并执行它,测试完成需要多长时间,假设测试仅在作业完成后关闭? / p>
上述测试仅检查第四点:我如何测试其他点?我想这只是隐含的,如果作业被执行,那么它们已经排队并推送到Redis之前。
答案 0 :(得分:1)
您的测试应该测试您的代码,而不是Sidekiq。执行手动测试以验证所有内容是否已集成禁用模式可以测试1和2,您的测试可以直接验证4。 3是手动完成的。