void () { NonBlockingReadActionImpl.waitForAsyncTaskCompletion(); PsiFileFactory factory = PsiFileFactory.getInstance(getProject()); List<PsiFile> files = new ArrayList<>(); for (int i = 0; i < 90; i++) { files.add(factory.createFileFromText("a.xml", XMLLanguage.INSTANCE, "<a><b><c/></b></a>", false, false)); } AtomicInteger attempts = new AtomicInteger(); CancellablePromise<Void> future = ReadAction.nonBlocking(() -> { attempts.incrementAndGet(); for (PsiFile file : files) { TimeoutUtil.sleep(1); Document document = FileDocumentManager.getInstance().getDocument(file.getViewProvider().getVirtualFile()); document.insertString(0, " "); for (PsiElement element : SyntaxTraverser.psiTraverser(file)) { ProgressManager.checkCanceled(); assertNotNull(element.getTextRange()); } } }).submit(AppExecutorUtil.getAppExecutorService()); PlatformTestUtil.waitForFuture(future, 10_000); assertTrue(String.valueOf(attempts), attempts.get() < 10); }