void () { final long warmupEnd = System.currentTimeMillis() + 1000; checkCanceledCalled = false; final ProgressIndicatorBase myIndicator = new ProgressIndicatorBase(); taskCanceled = taskSucceeded = false; exception = null; final long end = warmupEnd + 10000; Future<?> future = ((ProgressManagerImpl)ProgressManager.getInstance()).runProcessWithProgressAsynchronously( new Task.Backgroundable(getProject(), "Xxx") { @Override public void run(@NotNull ProgressIndicator indicator) { try { ApplicationManager.getApplication().assertIsNonDispatchThread(); assertSame(indicator, myIndicator); while (System.currentTimeMillis() < end) { ProgressManager.checkCanceled(); } } catch (ProcessCanceledException e) { exception = e; checkCanceledCalled = true; throw e; } catch (RuntimeException | Error e) { exception = e; throw e; } } @Override public void onCancel() { taskCanceled = true; } @Override public void onSuccess() { taskSucceeded = true; } }, myIndicator, null); ThreadingAssertions.assertEventDispatchThread(); while (!future.isDone()) { if (System.currentTimeMillis() < warmupEnd) { assertFalse(checkCanceledCalled); } else { myIndicator.cancel(); } } // invokeLater in runProcessWithProgressAsynchronously UIUtil.dispatchAllInvocationEvents(); assertTrue(checkCanceledCalled); assertFalse(taskSucceeded); assertTrue(taskCanceled); assertTrue(String.valueOf(exception), exception instanceof ProcessCanceledException); }