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); Thread.sleep(5000);
fail("Exception expected"); fail("Exception expected");
} catch (InterruptedException e) { } catch (InterruptedException e) {
long end = System.currentTimeMillis();
assertEquals(Thread.currentThread(), mainThread); assertEquals(Thread.currentThread(), mainThread);
assertFalse(mainThread.isInterrupted()); 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(); long start = System.currentTimeMillis();
queue.put(3); queue.put(3);
long end = System.currentTimeMillis(); 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()); assertEquals(3, queue.remove().intValue());
} }
@ -127,7 +127,7 @@ public class ArrayBlockingQueueTest {
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
int b = queue.take(); 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(1, a);
assertEquals(2, b); assertEquals(2, b);
} }