Skip to content

Commit

Permalink
Measure elapsed time with System.nanoTime() in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Michael <[email protected]>

Closes junit-team#3621
  • Loading branch information
bjmi authored and sbrannen committed Dec 30, 2023
1 parent 6ae587f commit 8baf93c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ void assertTimeoutWithMessageSupplierForSupplierThatCompletesAfterTheTimeout() {
* Take a nap for 100 milliseconds.
*/
private void nap() throws InterruptedException {
long start = System.currentTimeMillis();
long start = System.nanoTime();
// workaround for imprecise clocks (yes, Windows, I'm talking about you)
do {
Thread.sleep(100);
} while (System.currentTimeMillis() - start < 100);
} while (System.nanoTime() - start < 100_000_000L);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ internal class KotlinAssertTimeoutAssertionsTests {
* Take a nap for 100 milliseconds.
*/
private fun nap() {
val start = System.currentTimeMillis()
val start = System.nanoTime()
// workaround for imprecise clocks (yes, Windows, I'm talking about you)
do {
Thread.sleep(100)
} while (System.currentTimeMillis() - start < 100)
} while (System.nanoTime() - start < 100_000_000L)
}

private fun waitForInterrupt() {
Expand Down

0 comments on commit 8baf93c

Please sign in to comment.