retry_on在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

它从不进入discard_on块而是进入retry_on块。

错误

Failure/Error:
expected: 1 time with arguments: xxx
received: 0 times

retry_on是否首先执行?还是因为ConnectionErrors继承自StandardError

提前感谢

我认为您需要替换"执行";用";perform_now";引发ConnectionErrors:Error

allow_any_instance_of(described_class).to receive(:perform_now).and_raise(ConnectionErrors::Error)

相关内容

  • 没有找到相关文章

最新更新