From 8212ba127d8a4e2b653ace0e9a2931b0cac5fc6b Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 26 Dec 2016 15:32:08 +0300 Subject: [PATCH] blinking (due to sudden cpu load spikes) fixed --- .../AppScheduledExecutorServiceTest.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AppScheduledExecutorServiceTest.java b/platform/platform-tests/testSrc/com/intellij/util/concurrency/AppScheduledExecutorServiceTest.java index dc1fe97485a2..ac06e26975bf 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AppScheduledExecutorServiceTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/concurrency/AppScheduledExecutorServiceTest.java @@ -38,7 +38,6 @@ public class AppScheduledExecutorServiceTest extends TestCase { public void testDelayedWorks() throws InterruptedException { final AppScheduledExecutorService service = new AppScheduledExecutorService(getName()); - final List log = Collections.synchronizedList(new ArrayList<>()); assertFalse(service.isShutdown()); assertFalse(service.isTerminated()); @@ -46,6 +45,7 @@ public class AppScheduledExecutorServiceTest extends TestCase { int delay = 1000; long start = System.currentTimeMillis(); + List log = Collections.synchronizedList(new ArrayList<>()); ScheduledFuture f1 = service.schedule(() -> { log.add(new LogInfo(1)); TimeoutUtil.sleep(10); @@ -80,12 +80,16 @@ public class AppScheduledExecutorServiceTest extends TestCase { assertEquals(String.valueOf(f3.isDone()), elapsed > delay, f3.isDone()); assertTrue(f4.isDone()); - TimeoutUtil.sleep(delay/2+500); - assertTrue(f1.isDone()); - assertTrue(f2.isDone()); - assertTrue(f3.isDone()); - assertTrue(f4.isDone()); - + TimeoutUtil.sleep(delay/2); + long time = System.currentTimeMillis(); + while (!f1.isDone() || + !f2.isDone() || + !f3.isDone() || + !f4.isDone()) { + if (System.currentTimeMillis() > time + 10000) { + throw new AssertionError("Unfinished after 10 seconds"); + } + } assertEquals(4, log.size()); assertEquals(4, log.get(0).runnable); @@ -145,7 +149,6 @@ public class AppScheduledExecutorServiceTest extends TestCase { public void testDelayedTasksReusePooledThreadIfExecuteAtDifferentTimes() throws InterruptedException, ExecutionException { final AppScheduledExecutorService service = new AppScheduledExecutorService(getName()); - final List log = Collections.synchronizedList(new ArrayList<>()); // pre-start one thread Future future = service.submit(EmptyRunnable.getInstance()); future.get(); @@ -154,6 +157,7 @@ public class AppScheduledExecutorServiceTest extends TestCase { int delay = 500; + List log = Collections.synchronizedList(new ArrayList<>()); ScheduledFuture f1 = service.schedule((Runnable)() -> log.add(new LogInfo(1)), delay, TimeUnit.MILLISECONDS); ScheduledFuture f2 = service.schedule((Runnable)() -> log.add(new LogInfo(2)), delay + 100, TimeUnit.MILLISECONDS); ScheduledFuture f3 = service.schedule((Runnable)() -> log.add(new LogInfo(3)), delay + 200, TimeUnit.MILLISECONDS); @@ -221,8 +225,9 @@ public class AppScheduledExecutorServiceTest extends TestCase { )); TimeoutUtil.sleep(delay); long start = System.currentTimeMillis(); - while (!service.delayQueue.isEmpty() && System.currentTimeMillis() < start + 20000) { + while (!service.delayQueue.isEmpty()) { // wait till all tasks transferred to backend + if (System.currentTimeMillis() > start + 20000) throw new AssertionError("Not transferred after 20 seconds"); } List queuedTasks = new ArrayList<>(service.delayQueue); if (!queuedTasks.isEmpty()) {