Skip to content

Commit

Permalink
Changes SyncSpec#awaitTimeout to use nano time for latch await times
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCipher committed Nov 25, 2019
1 parent e662c3d commit f8787d8
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ public void awaitTrap() throws InterruptedException {

@Test
public void awaitTimeout() throws InterruptedException {
final long timeout = 200L;
final Sync<Object> sync = new Sync<Object>();
final long t0 = System.currentTimeMillis();
long timeout = 200L;
final Sync<Object> sync = new Sync<>();
final long t0 = System.nanoTime();

try {
sync.await(timeout);
fail();
} catch (SyncException e) {
final long dt = System.currentTimeMillis() - t0;
assertTrue(dt > timeout);
assertTrue(dt < 2L * timeout);
final long dt = System.nanoTime() - t0;

timeout *= 1e6;

assertTrue(dt > timeout, "Timeout too soon: dt: " + dt);
assertTrue(dt < 2L * timeout, "long too soon: dt: " + dt);
}
}

Expand Down

0 comments on commit f8787d8

Please sign in to comment.