我们有两个工人,如下所示:
class WorkerOne
include Sidekiq::Worker
def perform(arg_1, arg_2)
# some calculation figure out arg_3
WorkerTwo.perform_async(arg_3, arg_2)
end
end
class WorkerTwo
include Sidekiq::Worker
def perform(arg_3, arg_2)
# some heavy lifting
end
end
我们需要测试一下,当WorkerOne
被执行时,WorkerTwo
是否也入队了?我们尝试使用Sidekiq::Testing.inline!
来执行WorkerOne.perform_async(arg_1, arg_2)
AsWorkerTwo.perform_async(arg_3, arg_2)
从 WorkerOne 内部执行,我们尝试测试WorkerTwo.jobs
数组长度以从 更改0
为1
,假设作业是从内部排队的WorkerOne
,但它没有改变。我们在测试示例中使用了以下期望:
expect{WorkerOne.perform_async(task.id, user.id)}.to change(WorkerTwo.jobs, :size).by(1)
得到以下错误
expected `Array#size` to have changed by 1, but was changed by 0
请就所使用的方法提供任何建议和反馈。