[英]does retry_on get excuted first before discard_on?
语境:
我有一份工作可以捕获这些配置的一些错误
class CheckBankStatusJob < BaseJob
discard_on(ConnectionErrors::Error) do
Logger.new(STDOUT).warn("Connection Error!")
end
retry_on(
BankError::NoResponseData,
StandardError,
wait: 5.seconds,
)
end
ConnectionErrors
继承自StandardError
BankError::NoResponseData
继承自StandardError
我想测试 rspec 中的discard_on
事件
it "logs down when RemoteErrors::Error" do
allow_any_instance_of(described_class).to receive(:perform).and_raise(ConnectionErrors::Error)
expect_any_instance_of(Logger).to receive(:warn).with("Connection Error!")
described_class.perform_now
end
它永远不会 go 到discard_on
块,而是转到retry_on
块。
错误
Failure/Error:
expected: 1 time with arguments: xxx
received: 0 times
retry_on
是否首先执行? 或者是因为ConnectionErrors
继承自StandardError
?
提前致谢
我认为您需要将“perform”替换为“perform_now”以引发 ConnectionErrors::Error
allow_any_instance_of(described_class).to receive(:perform_now).and_raise(ConnectionErrors::Error)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.