-
Notifications
You must be signed in to change notification settings - Fork 183
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
Deprecate syncUninterruptibly() and awaitRequestNUninterruptibly() in tests #1756
Deprecate syncUninterruptibly() and awaitRequestNUninterruptibly() in tests #1756
Conversation
Motivation: - it discards InterruptedException silently so jUnit5 won't be able to stop tests whose timeout expires. Modifications: - Change all usages of awaitRequestNUninterruptibly() to awaitRequestN(). - add @deprecated to awaitRequestNUninterruptibly() Result: InterruptedException is no longer silently discarded, meaning jUnit5 will be able to abort the timeouted test.
Motivation: Currently netty's syncUninterruptibly() does not propogate Exceptions, meaning that jUnit5 is not able to stop timeouted tests. Modifications: - change the uses of syncUninterruptibly() to sync() - on safeSync() use Callable instead of Runnable, because Runnable is unable to throw exception Result: All Exceptions should be propogated to the top level and in the case of timeout the test be aborted.
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.
Great change! Thank you @Krupskis!
One comment, then LGTM.
Remaining answers:
- Why the N in awaitRequestN()?
Reactive Streams specification defines a method void request(long n)
for Subscription.
The word "request" is used in different contexts, we decided to add N at the end to highlight it's related to requesting N elements for Reactive Streams. Just found this convenient, no other reasons.
- I couldn't figure out what the function of
safeSync()
, so I changed it to useCallable
, could someone explain what it does in a bit more in depth?
Good question! Let's take an example from StreamObserverTest
:
@AfterEach
void teardown() throws Exception {
safeSync(() -> serverAcceptorChannel.close().sync());
safeSync(() -> serverEventLoopGroup.shutdownGracefully(0, 0, MILLISECONDS).sync());
safeClose(client);
}
Without safeSync
, if the first line throws, we will never close serverEventLoopGroup
and client
. safeSync
helps to make sure we continue teardown even if any of the lines throw an exeption.
runnable.run(); | ||
callable.call(); | ||
} catch (InterruptedException e) { | ||
throw e; |
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.
- Doesn’t safeClose() in HttpsProxyTest also not Propagate the InterruptedException, which might result in timeouts as well?
Good catch! You are right. Also, before re-throwing the InterruptedException
, we should reset interrupted
flag:
Thread.currentThread().interrupt();
throw e;
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.
Good catch, forgot that it resets the value :)
Motivation: Thrown InterruptedException means that the interrupted flag was reset for the Thread. Modifications: - reset the interrupted flag Result: The flag value is preserved
@idelpivnitskiy thanks for the answers, all is clear now. |
Thank you @Krupskis! |
…` in tests (#1756) Motivation: Currently netty's syncUninterruptibly() and awaitRequestNUninterruptibly() do not propagate `InterruptedException`, meaning that jUnit5 is not able to stop timeouted tests. Modifications: - change the uses of `syncUninterruptibly()` to `sync()` - on `safeSync()` use `Callable` instead of `Runnable`, because `Runnable` is unable to throw exception; - Change all usages of `awaitRequestNUninterruptibly()` to `awaitRequestN()`; - add `@Deprecated` to `awaitRequestNUninterruptibly()`; Result: `InterruptedException` is no longer silently discarded, meaning jUnit5 will be able to abort the timeouted test.
Motivation:
Currently netty's syncUninterruptibly() and
awaitRequestNUninterruptibly() do not
propogate
InterruptedException
, meaning that jUnit5 is notable to stop timeouted tests.
Modifications:
syncUninterruptibly()
tosync()
safeSync()
useCallable
instead ofRunnable
, becauseRunnable
is unable to throw exception;awaitRequestNUninterruptibly()
to
awaitRequestN()
;@Deprecated
toawaitRequestNUninterruptibly()
;Result:
InterruptedException
is no longer silently discarded,meaning jUnit5 will be able to abort the timeouted test.
Related to #1684.
Questions from my side:
Propagate the InterruptedException, which might
result in timeouts as well?
safeSync(), so I changed it to use Callable,
could someone explain what it does in
a bit more in depth?