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