Fix flaky test

This commit is contained in:
Alexey Andreev 2018-01-07 16:04:38 +03:00
parent 0c8013dfcf
commit 8e4b84545f

View File

@ -39,23 +39,21 @@ public class ThreadTest {
public void sleepInterrupted() {
long start = System.currentTimeMillis();
final Thread mainThread = Thread.currentThread();
new Thread() {
@Override public void run() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// ok
}
mainThread.interrupt();
new Thread(() -> {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// ok
}
}.start();
mainThread.interrupt();
}).start();
try {
Thread.sleep(500);
Thread.sleep(5000);
fail("Exception expected");
} catch (InterruptedException e) {
assertEquals(Thread.currentThread(), mainThread);
assertFalse(mainThread.isInterrupted());
assertTrue(System.currentTimeMillis() - start < 150);
assertTrue(System.currentTimeMillis() - start < 500);
}
}