-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduce lambda based timeout assertions #439
Conversation
@junit-team/junit-lambda, please let me know your thoughts on the PR. |
* <em>Asserts</em> that execution of the supplied {@code executable} | ||
* completes before the given {@code timeout} is exceeded. | ||
* | ||
* <p>Note: the executable will be executed in the same thread as that |
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.
nit: space between "as" and "that". same for other timeout methods
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! (y)
I'll fix it.
2309eda
to
a7e71d8
Compare
This commit introduces assertTimeout() methods in Assertions that support both lazy and preemptive timeouts for blocks of code supplied as lambda expressions. For example, the following assertion would pass: assertTimeout(ofMillis(500), () -> Thread.sleep(10)); Whereas, the following assertion would fail: assertTimeout(ofMillis(10), () -> Thread.sleep(500)); The above examples execute the code block in the same thread as the caller. To perform the same assertions and have the code executed in a separate thread and then preemptively aborted, the above can be rewritten as follows. assertTimeoutPreemptively(ofMillis(10), () -> Thread.sleep(500)); Issue: #438
a7e71d8
to
0759a68
Compare
Looks good to me! Great to finally have support for timeouts! 👍 |
Thanks for the review, and... I couldn't agree more: it definitely is great to finally have official support for timeouts in JUnit 5! |
Overview
This commit introduces
assertTimeout()
methods inAssertions
that support both lazy and preemptive timeouts for blocks of code supplied as lambda expressions.For example, the following assertion would pass:
assertTimeout(ofMillis(500), () -> Thread.sleep(10));
Whereas, the following assertion would fail:
assertTimeout(ofMillis(10), () -> Thread.sleep(500));
The above examples execute the code block in the same thread as the caller. To perform the same assertion as the last example and have the code executed in a separate thread and then preemptively aborted, the above can be rewritten as follows.
assertTimeoutPreemptively(ofMillis(10), () -> Thread.sleep(500));
Issue: #438
I hereby agree to the terms of the JUnit Contributor License Agreement.