IJPL-578 Explicitly wait for smart mode in tests (tests/platform)

GitOrigin-RevId: e5d8e6500db5d4b1b3ca7e57d157573262404212
This commit is contained in:
Andrei.Kuznetsov
2024-01-31 00:01:00 +00:00
committed by intellij-monorepo-bot
parent 0793aba21c
commit 41fc6333e3
8 changed files with 30 additions and 10 deletions
@@ -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()
}
@@ -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) {
@@ -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()
}
}
@@ -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) {
@@ -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)
}
@@ -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
}
@@ -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<VirtualFile> 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;
}
}
@@ -796,6 +796,7 @@ public abstract class DependenciesIndexedStatusServiceBaseTest {
ApplicationManager.getApplication().runWriteAction(() -> {
ProjectRootManagerEx.getInstanceEx(getProject()).makeRootsChange(EmptyRunnable.getInstance(), info);
});
IndexingTestUtil.waitUntilIndexesAreReady(getProject());
}
protected void assertNothingToRescanAndFinishIndexing() {