-
Notifications
You must be signed in to change notification settings - Fork 965
Fix RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled
#6399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled
#6399
Conversation
f021914
to
5316498
Compare
…#6382) Motivation: I thought the previous modification #6354 would fix the flakiness, but it turned out it didn't. The first attempt may not be cancelled by `res.cancel(true)` because of the race between an event loop and the main thread. https://github.com/line/armeria/blob/a0e2225cb7aac6b229b86e25e9b2f34633a9f45b/thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/client/retry/RetryingRpcClientTest.java#L354-L356 Therefore, I propose removing the flaky assertions and adding a new clear assertion that verifies retry occurs only once. Modifications: - Remove flaky assertions in `RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled()` Result: Make CI stable
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/client/retry/RetryingRpcClientTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
thrift/thrift0.13/src/test/java/com/linecorp/armeria/it/client/retry/RetryingRpcClientTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6399 +/- ##
============================================
- Coverage 74.46% 74.09% -0.37%
- Complexity 22234 22993 +759
============================================
Files 1963 2061 +98
Lines 82437 86125 +3688
Branches 10764 11310 +546
============================================
+ Hits 61385 63813 +2428
- Misses 15918 16898 +980
- Partials 5134 5414 +280 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled
is brittle because it assumes that cancelling the response after delegating toRetryingRpcClient
will always result in exactly one attempt. However, there is no guarantee about the number of attempts made betweenres = delegate.execute()
andres.cancel()
.I propose rewriting the test to verify two guarantees:
RetryingRpcClient.execute
is called,RetryingRpcClient
performs no attempts.RetryingRpcClient.execute
is called,RetryingRpcClient
performs at most one additional attempt after cancellation.The first guarantee is straightforward to test. For the second, we currently lack a way to signal cancellation before invoking
RetryingRpcClient.execute(ctx, req)
, since we do not yet have a handle to the response. Additionally,RetryingRpcClient
currently ignoresctx.isCancelled()
during retries.To address this, I propose adding a
ctx.isCancelled()
check before each retry attempt. This allows thedoNotRetryWhenResponseIsCancelled
test to callctx.cancel()
before proceeding through the decorator chain, ensuringRetryingRpcClient
observes the cancelled state and skips further retries.See also this comment for additional context.
Modifications
ctx.isCancelled()
check inRetryingRpcClient
before scheduling each retry.RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled
to cancel the request/response with varying delays.Result
RetryingRpcClientTest.doNotRetryWhenResponseIsCancelled
is no longer flaky.RetryingRpcClient
respectsctx.isCancelled