From 41fc6333e3ece862955eaf6501052a07b39f106d Mon Sep 17 00:00:00 2001 From: "Andrei.Kuznetsov" Date: Mon, 29 Jan 2024 14:23:49 +0100 Subject: [PATCH] IJPL-578 Explicitly wait for smart mode in tests (tests/platform) GitOrigin-RevId: e5d8e6500db5d4b1b3ca7e57d157573262404212 --- ...teRCInArbitraryFilesAfterProjectModelChangesTest.kt | 9 +++++---- .../util/indexing/UnindexedFilesScannerTest.kt | 2 ++ .../com/intellij/ide/plugins/DynamicPluginsTestUtil.kt | 10 ++++++++-- .../roots/impl/indexing/IndexableFilesBaseTest.kt | 7 +++---- .../roots/impl/indexing/IndexableFilesRegularTest.kt | 4 ++++ .../openapi/roots/impl/indexing/ProjectStructureDsl.kt | 2 ++ .../com/intellij/util/indexing/FileTypeIndexTest.java | 5 +++++ .../DependenciesIndexedStatusServiceBaseTest.java | 1 + 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/platform/execution-impl/testSources/com/intellij/execution/UpdateRCInArbitraryFilesAfterProjectModelChangesTest.kt b/platform/execution-impl/testSources/com/intellij/execution/UpdateRCInArbitraryFilesAfterProjectModelChangesTest.kt index b22e1fa6ee18..29afb4e96673 100644 --- a/platform/execution-impl/testSources/com/intellij/execution/UpdateRCInArbitraryFilesAfterProjectModelChangesTest.kt +++ b/platform/execution-impl/testSources/com/intellij/execution/UpdateRCInArbitraryFilesAfterProjectModelChangesTest.kt @@ -3,11 +3,8 @@ package com.intellij.execution import com.intellij.openapi.application.impl.NonBlockingReadActionImpl import com.intellij.openapi.roots.ModuleRootModificationUtil -import com.intellij.testFramework.ApplicationRule -import com.intellij.testFramework.PsiTestUtil -import com.intellij.testFramework.TestLoggerFactory +import com.intellij.testFramework.* import com.intellij.testFramework.rules.ProjectModelRule -import com.intellij.testFramework.runInEdtAndWait import org.assertj.core.api.Assertions.assertThat import org.junit.ClassRule import org.junit.Rule @@ -33,9 +30,11 @@ class UpdateRCInArbitraryFilesAfterProjectModelChangesTest { assertThat(runConfigurations).isEmpty() val module = projectModel.createModule("m") ModuleRootModificationUtil.addContentRoot(module, file.parent.path) + IndexingTestUtil.waitUntilIndexesAreReady(projectModel.project) assertThat(runConfigurations.single().name).isEqualTo("a") projectModel.removeModule(module) runInEdtAndWait { NonBlockingReadActionImpl.waitForAsyncTaskCompletion() } + IndexingTestUtil.waitUntilIndexesAreReady(projectModel.project) assertThat(runConfigurations).isEmpty() } @Test @@ -48,11 +47,13 @@ class UpdateRCInArbitraryFilesAfterProjectModelChangesTest { PsiTestUtil.addSourceRoot(module, srcRoot) PsiTestUtil.addExcludedRoot(module, excludedRoot) projectModel.baseProjectDir.newVirtualFile("m/exc/src/b.run.xml", generateRunXmlFileText("b")) + IndexingTestUtil.waitUntilIndexesAreReady(projectModel.project) assertThat(runConfigurations.single().name).isEqualTo("b") PsiTestUtil.removeSourceRoot(module, srcRoot) runInEdtAndWait { NonBlockingReadActionImpl.waitForAsyncTaskCompletion() } + IndexingTestUtil.waitUntilIndexesAreReady(projectModel.project) assertThat(runConfigurations).isEmpty() } diff --git a/platform/lang-impl/testSources/com/intellij/util/indexing/UnindexedFilesScannerTest.kt b/platform/lang-impl/testSources/com/intellij/util/indexing/UnindexedFilesScannerTest.kt index ce74f41b699e..49091dce98e3 100644 --- a/platform/lang-impl/testSources/com/intellij/util/indexing/UnindexedFilesScannerTest.kt +++ b/platform/lang-impl/testSources/com/intellij/util/indexing/UnindexedFilesScannerTest.kt @@ -64,6 +64,7 @@ class UnindexedFilesScannerTest { @Before fun setup() { project = p.project + IndexingTestUtil.waitUntilIndexesAreReady(project) testRootDisposable = Disposer.newCheckedDisposable("ScanningAndIndexingTest") } @@ -308,6 +309,7 @@ class UnindexedFilesScannerTest { } tumbler.turnOn() } + IndexingTestUtil.waitUntilIndexesAreReady(project) } private fun scanAndIndexFiles(filesAndDirs: SingleRootIndexableFilesIterator) { diff --git a/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTestUtil.kt b/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTestUtil.kt index 6dc1df8cae52..14540c7807eb 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTestUtil.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTestUtil.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.extensions.PluginId import com.intellij.openapi.util.BuildNumber import com.intellij.openapi.util.io.FileUtil +import com.intellij.testFramework.IndexingTestUtil import com.intellij.testFramework.assertions.Assertions.assertThat import kotlinx.coroutines.runBlocking import java.nio.file.Files @@ -58,7 +59,9 @@ fun loadExtensionWithText(extensionTag: String, ns: String = "com.intellij"): Di return loadPluginWithText( pluginBuilder = PluginBuilder().extensions(extensionTag, ns), path = FileUtil.createTempDirectory("test", "test", true).toPath(), - ) + ).also { + IndexingTestUtil.waitUntilIndexesAreReadyInAllOpenedProjects() + } } internal fun loadPluginWithText( @@ -74,6 +77,7 @@ internal fun loadPluginWithText( assertThat(DynamicPlugins.checkCanUnloadWithoutRestart(descriptor)).isNull() try { DynamicPlugins.loadPlugin(pluginDescriptor = descriptor) + IndexingTestUtil.waitUntilIndexesAreReadyInAllOpenedProjects() } catch (e: Exception) { unloadAndUninstallPlugin(descriptor) @@ -120,5 +124,7 @@ internal fun unloadAndUninstallPlugin(descriptor: IdeaPluginDescriptorImpl): Boo return DynamicPlugins.unloadPlugin( descriptor, DynamicPlugins.UnloadPluginOptions(disable = false), - ) + ).also { + IndexingTestUtil.waitUntilIndexesAreReadyInAllOpenedProjects() + } } \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesBaseTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesBaseTest.kt index d5e360c7600a..722fa156ff3a 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesBaseTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesBaseTest.kt @@ -15,11 +15,8 @@ import com.intellij.openapi.vfs.VirtualFileWithId import com.intellij.psi.search.FileTypeIndex import com.intellij.psi.search.FilenameIndex import com.intellij.psi.search.GlobalSearchScope -import com.intellij.testFramework.ApplicationRule -import com.intellij.testFramework.DisposableRule -import com.intellij.testFramework.EdtRule +import com.intellij.testFramework.* import com.intellij.testFramework.ExtensionTestUtil.maskExtensions -import com.intellij.testFramework.RunsInEdt import com.intellij.testFramework.assertions.Assertions import com.intellij.testFramework.rules.ProjectModelRule import com.intellij.testFramework.rules.TempDirectory @@ -72,6 +69,8 @@ abstract class IndexableFilesBaseTest { (IndexableSetContributor.EP_NAME.point as ExtensionPointImpl<*>).unregisterExtensions({ _, _ -> false }, false) (AdditionalLibraryRootsProvider.EP_NAME.point as ExtensionPointImpl<*>).unregisterExtensions({ _, _ -> false }, false) } + + IndexingTestUtil.waitUntilIndexesAreReady(project) } protected fun assertIndexableFiles(vararg expectedFiles: VirtualFile) { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesRegularTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesRegularTest.kt index b2d6dc7a950c..789d5c4b776b 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesRegularTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/IndexableFilesRegularTest.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.vfs.VirtualFileWithId import com.intellij.psi.impl.cache.CacheManager import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.UsageSearchContext +import com.intellij.testFramework.IndexingTestUtil import com.intellij.testFramework.RunsInEdt import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.UsefulTestCase.assertSameElements @@ -204,6 +205,7 @@ class IndexableFilesRegularTest : IndexableFilesBaseTest() { setOf(additionalRootsFile) } maskIndexableSetContributors(contributor) + IndexingTestUtil.waitUntilIndexesAreReady(project) assertIndexableFiles(additionalProjectRootJava.file, additionalRootJava.file) assertIdIndexContainsWord(additionalRootJava.file, "AdditionalRoot") assertIdIndexContainsWord(additionalProjectRootJava.file, "AdditionalProjectRoot") @@ -318,6 +320,7 @@ class IndexableFilesRegularTest : IndexableFilesBaseTest() { } } ModuleRootModificationUtil.addContentRoot(module, contentRootDirSpec.file.path) + IndexingTestUtil.waitUntilIndexesAreReady(project) assertFilesInIndexableFilesFilter(contentFile, sourceFile) @@ -330,6 +333,7 @@ class IndexableFilesRegularTest : IndexableFilesBaseTest() { sourceFile2 = file("SourceFile2.java", "class SourceFile2 {}") } ModuleRootModificationUtil.addContentRoot(module, secondContentRoot.path) + IndexingTestUtil.waitUntilIndexesAreReady(project) assertFilesInIndexableFilesFilter(contentFile, sourceFile, contentFile2, sourceFile2) } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/ProjectStructureDsl.kt b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/ProjectStructureDsl.kt index aad927971f9e..88712ab57cb8 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/ProjectStructureDsl.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/roots/impl/indexing/ProjectStructureDsl.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.IoTestUtil import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile +import com.intellij.testFramework.IndexingTestUtil import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.rules.ProjectModelRule import org.jetbrains.jps.model.java.JavaResourceRootType @@ -280,6 +281,7 @@ fun ProjectModelRule.createJavaModule(moduleName: String, content: ModuleContent val directorySpec = DirectorySpec(rootPath) ModuleContentBuilderImpl(module, directorySpec).content() directorySpec.generateTo(moduleRoot) + IndexingTestUtil.waitUntilIndexesAreReady(project) return module } diff --git a/platform/platform-tests/testSrc/com/intellij/util/indexing/FileTypeIndexTest.java b/platform/platform-tests/testSrc/com/intellij/util/indexing/FileTypeIndexTest.java index a46ce0b4bfac..92444ab841b2 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/indexing/FileTypeIndexTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/indexing/FileTypeIndexTest.java @@ -18,6 +18,7 @@ import com.intellij.psi.search.FileTypeIndex; import com.intellij.psi.search.FileTypeIndexImpl; import com.intellij.psi.search.FileTypeIndexImplBase; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.testFramework.IndexingTestUtil; import com.intellij.testFramework.LightPlatformTestCase; import com.intellij.testFramework.fixtures.BasePlatformTestCase; import org.jetbrains.annotations.NotNull; @@ -39,6 +40,7 @@ public class FileTypeIndexTest extends BasePlatformTestCase { int version = index.getVersion(); Disposable disposable = Disposer.newDisposable(); FileType foo = registerFakeFileType(getTestName(false), "test", disposable); + //PsiTestUtil.waitUntilIndexesAreReady(getProject()); try { assertEquals(version, index.getVersion()); Collection files = FileTypeIndex.getFiles(foo, GlobalSearchScope.allScope(getProject())); @@ -47,6 +49,7 @@ public class FileTypeIndexTest extends BasePlatformTestCase { } finally { Disposer.dispose(disposable); + IndexingTestUtil.waitUntilIndexesAreReady(getProject()); } assertEquals(PlainTextFileType.INSTANCE, FileTypeIndex.getIndexedFileType(file, getProject())); assertEmpty(FileTypeIndex.getFiles(foo, GlobalSearchScope.allScope(getProject()))); @@ -76,6 +79,7 @@ public class FileTypeIndexTest extends BasePlatformTestCase { assertEmpty(FileTypeIndex.getFiles(smth1, GlobalSearchScope.allScope(getProject()))); assertOneElement(FileTypeIndex.getFiles(smth2, GlobalSearchScope.allScope(getProject()))); Disposer.dispose(disposable); + IndexingTestUtil.waitUntilIndexesAreReady(getProject()); assertEquals(PlainTextFileType.INSTANCE, FileTypeIndex.getIndexedFileType(file, getProject())); } @@ -175,6 +179,7 @@ public class FileTypeIndexTest extends BasePlatformTestCase { }; ((FileTypeManagerImpl)FileTypeManager.getInstance()).registerFileType(foo, List.of(), parent, PluginManagerCore.getPlugin(PluginManagerCore.CORE_ID)); + IndexingTestUtil.waitUntilIndexesAreReadyInAllOpenedProjects(); return foo; } } diff --git a/platform/platform-tests/testSrc/com/intellij/util/indexing/dependenciesCache/DependenciesIndexedStatusServiceBaseTest.java b/platform/platform-tests/testSrc/com/intellij/util/indexing/dependenciesCache/DependenciesIndexedStatusServiceBaseTest.java index 9ef9d5875da1..ed8624ab62b8 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/indexing/dependenciesCache/DependenciesIndexedStatusServiceBaseTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/indexing/dependenciesCache/DependenciesIndexedStatusServiceBaseTest.java @@ -796,6 +796,7 @@ public abstract class DependenciesIndexedStatusServiceBaseTest { ApplicationManager.getApplication().runWriteAction(() -> { ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.getInstance(), info); }); + IndexingTestUtil.waitUntilIndexesAreReady(getProject()); } protected void assertNothingToRescanAndFinishIndexing() {