void () { runWithReparseDelay(0, () -> { runHeavyProcessing = false; try { Set<Editor> applied = Collections.synchronizedSet(new HashSet<>()); Set<Editor> collected = Collections.synchronizedSet(new HashSet<>()); registerFakePass(applied, collected); configureByText(PlainTextFileType.INSTANCE, ""); Editor editor = getEditor(); EditorTracker editorTracker = EditorTracker.getInstance(myProject); setActiveEditors(editor); while (HeavyProcessLatch.INSTANCE.isRunning()) { UIUtil.dispatchAllInvocationEvents(); } type("xxx"); // restart daemon assertTrue(editorTracker.getActiveEditors().contains(editor)); assertSame(editor, FileEditorManager.getInstance(myProject).getSelectedTextEditor()); // wait for the first pass to complete long start = System.currentTimeMillis(); while (myDaemonCodeAnalyzer.isRunning() || !applied.contains(editor)) { UIUtil.dispatchAllInvocationEvents(); if (System.currentTimeMillis() - start > 1000000) { fail("Too long waiting for daemon"); } } runHeavyProcessing = true; ApplicationManager.getApplication().executeOnPooledThread(() -> HeavyProcessLatch.INSTANCE.performOperation(HeavyProcessLatch.Type.Processing, "my own heavy op", ()-> { while (runHeavyProcessing) { } }) ); while (!HeavyProcessLatch.INSTANCE.isRunning()) { UIUtil.dispatchAllInvocationEvents(); } applied.clear(); collected.clear(); type("xxx"); // try to restart daemon start = System.currentTimeMillis(); while (System.currentTimeMillis() < start + 5000) { assertEmpty(applied); // it should not restart assertEmpty(collected); UIUtil.dispatchAllInvocationEvents(); } } finally { runHeavyProcessing = false; } }); }