Fix time-based test for worse timer resolution

This commit is contained in:
Alexey Andreev 2021-03-09 11:00:24 +03:00
parent fb81153ad2
commit bc9ad315ff
2 changed files with 4 additions and 3 deletions

View File

@ -51,9 +51,10 @@ public class ThreadTest {
Thread.sleep(5000);
fail("Exception expected");
} catch (InterruptedException e) {
long end = System.currentTimeMillis();
assertEquals(Thread.currentThread(), mainThread);
assertFalse(mainThread.isInterrupted());
assertTrue(System.currentTimeMillis() - start < 500);
assertTrue("Wait time " + (end - start), end - start < 5000);
}
}

View File

@ -102,7 +102,7 @@ public class ArrayBlockingQueueTest {
long start = System.currentTimeMillis();
queue.put(3);
long end = System.currentTimeMillis();
assertTrue("Wait time " + (end - start), start + 50 < end && start + 500 > end);
assertTrue("Wait time " + (end - start), start + 50 < end && start + 5000 > end);
assertEquals(3, queue.remove().intValue());
}
@ -127,7 +127,7 @@ public class ArrayBlockingQueueTest {
long end = System.currentTimeMillis();
int b = queue.take();
assertTrue("Wait time " + (end - start), start + 100 < end && start + 900 > end);
assertTrue("Wait time " + (end - start), start + 100 < end && start + 5000 > end);
assertEquals(1, a);
assertEquals(2, b);
}