void () { AtomicInteger attemptCount = new AtomicInteger(); int limit = 10; Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> { assertEquals("a", ReadAction.nonBlocking(() -> { if (attemptCount.incrementAndGet() < limit) { //noinspection InfiniteLoopStatement while (true) { ProgressManager.checkCanceled(); } } return "a"; }).executeSynchronously()); assertTrue(attemptCount.toString(), attemptCount.get() >= limit); }); while (attemptCount.get() < limit) { WriteAction.run(() -> {}); UIUtil.dispatchAllInvocationEvents(); TimeoutUtil.sleep(1); } waitForFuture(future); }