void (int delay) { @NotNull Application app = ApplicationManager.getApplication(); assertDispatchThreadWithoutWriteAccess(); Disposable tempDisposable = Disposer.newDisposable(); AtomicBoolean runnableInvoked = new AtomicBoolean(); AtomicBoolean pooledRunnableInvoked = new AtomicBoolean(); AtomicBoolean alarmInvoked1 = new AtomicBoolean(); AtomicBoolean alarmInvoked2 = new AtomicBoolean(); Alarm alarm = new Alarm(); Alarm pooledAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, tempDisposable); ModalityState initialModality = ModalityState.current(); alarm.addRequest(() -> { alarmInvoked1.set(true); app.invokeLater(() -> { runnableInvoked.set(true); alarm.addRequest(() -> alarmInvoked2.set(true), delay); }); }, delay); pooledAlarm.addRequest(() -> pooledRunnableInvoked.set(true), delay); UIUtil.dispatchAllInvocationEvents(); long start = System.currentTimeMillis(); try { boolean sleptAlready = false; while (!alarmInvoked2.get()) { AtomicBoolean laterInvoked = new AtomicBoolean(); app.invokeLater(() -> laterInvoked.set(true)); UIUtil.dispatchAllInvocationEvents(); assertTrue(laterInvoked.get()); TimeoutUtil.sleep(sleptAlready ? 10 : delay); sleptAlready = true; if (getMillisSince(start) > MAX_WAIT_TIME) { String queue = ((AppScheduledExecutorService)AppExecutorUtil.getAppScheduledExecutorService()).dumpQueue(); throw new AssertionError("Couldn't await alarm" + "; alarm passed=" + alarmInvoked1.get() + "; modality1=" + initialModality + "; modality2=" + ModalityState.current() + "; non-modal=" + (initialModality == ModalityState.nonModal()) + "; invokeLater passed=" + runnableInvoked.get() + "; pooled alarm passed=" + pooledRunnableInvoked.get() + "; app.disposed=" + app.isDisposed() + "; alarm.disposed=" + alarm.isDisposed() + "; alarm.requests=" + alarm.getActiveRequestCount() + "\n delayQueue=" + StringUtil.trimLog(queue, 1000) + "\n invocatorEdtQueue=" + LaterInvocator.getLaterInvocatorEdtQueue() ); } } } finally { Disposer.dispose(tempDisposable); } UIUtil.dispatchAllInvocationEvents(); }