Async: cover retry stop interleavings and classifier failures (X-QA-04)
This commit is contained in:
1 parent
fe231b0149
commit
65185f251c
1 file changed
+100
@@ -1181,3 +1181,103 @@ Void::Testing::Test async_retry_matches_blocking_schedule_same_seed()
|
||||
expect_eq(async_log.calls(), std::size_t{6});
|
||||
expect(async_log.times == blocking_log.times);
|
||||
}
|
||||
|
||||
Void::Testing::Test async_retry_backoff_stop_reason_mapping()
|
||||
{
|
||||
using R::RetryStopReason;
|
||||
|
||||
// A timeout from the backoff sleep is a deadline, not a user stop.
|
||||
expect(R::RetryStopReason::deadline_exceeded ==
|
||||
detail::retry_backoff_stop_reason(make_async_error(AsyncErrorCode::timeout)));
|
||||
|
||||
// Everything else is terminal and must never retry without a wait.
|
||||
for (const AsyncErrorCode code : {AsyncErrorCode::cancelled,
|
||||
AsyncErrorCode::stopped,
|
||||
AsyncErrorCode::closed,
|
||||
AsyncErrorCode::overloaded,
|
||||
AsyncErrorCode::backend_error,
|
||||
AsyncErrorCode::limit_exceeded}) {
|
||||
expect(R::RetryStopReason::stop_requested ==
|
||||
detail::retry_backoff_stop_reason(make_async_error(code)));
|
||||
}
|
||||
|
||||
// A non-Async domain error is treated conservatively as a stop.
|
||||
expect(R::RetryStopReason::stop_requested ==
|
||||
detail::retry_backoff_stop_reason(Void::Result::Error{
|
||||
Void::Result::ErrorKind::internal,
|
||||
"foreign domain",
|
||||
Void::Result::ErrorCode{.domain = 999, .value = 1}}));
|
||||
}
|
||||
|
||||
Void::Testing::Test async_retry_stop_poll_handshake_alternation()
|
||||
{
|
||||
// Both deterministic interleavings of "stop requested" and "timer polled"
|
||||
// must produce exactly one resume, one attempt and one terminal result.
|
||||
for (const bool stop_first : {true, false}) {
|
||||
ManualExecutor exec;
|
||||
ManualClock clock;
|
||||
auto q = make_queue(exec, clock);
|
||||
|
||||
std::stop_source source;
|
||||
int calls = 0;
|
||||
RetryProbe<IntOut> probe;
|
||||
auto task = collect(
|
||||
retry_async(constant_spec(10ms, 5),
|
||||
[&calls]() -> std::expected<int, std::string> {
|
||||
++calls;
|
||||
return std::unexpected{std::string{"e"}};
|
||||
},
|
||||
*q,
|
||||
OperationOptions{.stop = source.get_token()}),
|
||||
&probe);
|
||||
start(task);
|
||||
expect_eq(calls, 1);
|
||||
advance_clock(clock, 10ms);
|
||||
|
||||
if (stop_first) {
|
||||
expect(source.request_stop());
|
||||
(void)q->poll_expired();
|
||||
} else {
|
||||
expect_eq(q->poll_expired(), std::size_t{1});
|
||||
expect(source.request_stop());
|
||||
}
|
||||
|
||||
expect_eq(exec.drain(), std::size_t{1});
|
||||
expect(task.done());
|
||||
expect_stop(probe, R::RetryStopReason::stop_requested, 1);
|
||||
expect_eq(calls, 1);
|
||||
expect_eq(q->active_timers(), std::size_t{0});
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test async_retry_throwing_classifier_propagates()
|
||||
{
|
||||
ManualExecutor exec;
|
||||
ManualClock clock;
|
||||
auto q = make_queue(exec, clock);
|
||||
|
||||
int calls = 0;
|
||||
RetryProbe<IntOut> probe;
|
||||
auto classifier = [](const std::string&) -> R::AttemptOutcome {
|
||||
throw std::runtime_error{"classifier threw"};
|
||||
};
|
||||
auto task = collect(
|
||||
retry_async(constant_spec(10ms, 5),
|
||||
[&calls]() -> std::expected<int, std::string> {
|
||||
++calls;
|
||||
return std::unexpected{std::string{"e"}};
|
||||
},
|
||||
*q,
|
||||
{},
|
||||
classifier),
|
||||
&probe);
|
||||
start(task);
|
||||
|
||||
// The classifier exception escapes the retry task; nothing is retried and
|
||||
// no timer is left armed.
|
||||
expect(task.done());
|
||||
expect(probe.threw);
|
||||
expect_eq(probe.what, std::string{"classifier threw"});
|
||||
expect_eq(calls, 1);
|
||||
expect_eq(q->active_timers(), std::size_t{0});
|
||||
}
|
||||
Reference in new issue
Block a user