From 0fb89ef48e7a30dfaa5fc688fc0c6da85e8fb418 Mon Sep 17 00:00:00 2001 From: "Andrei.Kuznetsov" Date: Thu, 18 Jul 2024 17:45:18 +0200 Subject: [PATCH] IDEA-354670: IndexingTestUtil.waitNow should wait for indexing even if it was submitted during EDT events pumping GitOrigin-RevId: 96d306e82d1b6a79c5c6207daca427bfee0f6792 --- .../com/intellij/testFramework/IndexingTestUtil.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/IndexingTestUtil.kt b/platform/testFramework/src/com/intellij/testFramework/IndexingTestUtil.kt index bf80595da34d..f88e98acc4f9 100644 --- a/platform/testFramework/src/com/intellij/testFramework/IndexingTestUtil.kt +++ b/platform/testFramework/src/com/intellij/testFramework/IndexingTestUtil.kt @@ -64,8 +64,10 @@ class IndexingTestUtil(private val project: Project) { val scope = GlobalScope.childScope("Indexing waiter", Dispatchers.IO) val waiting = scope.launch { suspendUntilIndexesAreReady() } try { - PlatformTestUtil.waitWithEventsDispatching("Indexing timeout", { !waiting.isActive }, 600) - PlatformTestUtil.dispatchAllEventsInIdeEventQueue() // make sure that all the scheduled write actions are executed + do { + PlatformTestUtil.waitWithEventsDispatching("Indexing timeout", { !waiting.isActive }, 600) + } + while (dispatchAllEventsInIdeEventQueue()) // make sure that all the scheduled write actions are executed } finally { waiting.cancel() @@ -78,6 +80,14 @@ class IndexingTestUtil(private val project: Project) { } } + private fun dispatchAllEventsInIdeEventQueue(): Boolean { + var hasDispatchedEvents = false + while (PlatformTestUtil.dispatchNextEventIfAny() != null) { + hasDispatchedEvents = true + } + return hasDispatchedEvents + } + private fun shouldWait(): Boolean { val dumbService = DumbServiceImpl.getInstance(project)