Skip to content
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

Merged
merged 3 commits into from
Aug 30, 2021

Conversation

Krupskis
Copy link
Contributor

@Krupskis Krupskis commented Aug 26, 2021

Motivation:
Currently netty's syncUninterruptibly() and
awaitRequestNUninterruptibly() do not
propogate 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.

Related to #1684.

Questions from my side:

  1. Why the N in awaitRequestN()?
  2. Doesn’t safeClose() in HttpsProxyTest also not
    Propagate the InterruptedException, which might
    result in timeouts as well?
  3. I couldn't figure out what the function of
    safeSync(), so I changed it to use Callable,
    could someone explain what it does in
    a bit more in depth?

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.
@idelpivnitskiy idelpivnitskiy self-requested a review August 26, 2021 17:28
@bondolo bondolo added the technical debt Reduces technical debt label Aug 27, 2021
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a 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:

  1. 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.

  1. I couldn't figure out what the function of safeSync(), so I changed it to use Callable, 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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;

Copy link
Contributor Author

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
@Krupskis
Copy link
Contributor Author

@idelpivnitskiy thanks for the answers, all is clear now.

@idelpivnitskiy idelpivnitskiy merged commit 8e35022 into apple:main Aug 30, 2021
@idelpivnitskiy
Copy link
Member

Thank you @Krupskis!

idelpivnitskiy pushed a commit that referenced this pull request Aug 30, 2021
…` 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical debt Reduces technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants