testDynamicExtensions: FileBasedIndexSwitcher has to receive PluginUnloaded event.

Without receiving the event, FileBasedIndexImpl has null `myRegisteredIndexes` and cancels any attempt to `waitUntilIndicesAreInitialized`, which happens during project close, thus leading to half closed project and various leaks during the test.

GitOrigin-RevId: 7c7354fe4a721952af39faa0948d048319cbcf02
This commit is contained in:
Piotr Tomiak
2020-01-02 17:12:01 +00:00
committed by intellij-monorepo-bot
parent a1d6cccd5e
commit 66b413430f
@@ -72,6 +72,7 @@ public class _LastInSuiteTest extends TestCase {
Map<ExtensionPoint<?>, Collection<WeakReference<Object>>> extensions = collectDynamicNonPlatformExtensions();
unloadExtensionPoints(extensions.keySet());
startCorePluginUnload();
disposePluginDisposables();
ProjectManager pm = ProjectManager.getInstanceIfCreated();
if (pm != null) {
@@ -79,6 +80,7 @@ public class _LastInSuiteTest extends TestCase {
((CachedValuesManagerImpl) CachedValuesManager.getManager(project)).clearCachedValues();
}
}
finishCorePluginUnload();
GCUtil.tryGcSoftlyReachableObjects();
System.gc();
@@ -125,6 +127,9 @@ public class _LastInSuiteTest extends TestCase {
ep.unregisterExtensions((a, b) -> false, false);
});
}
}
private static void startCorePluginUnload() {
IdeaPluginDescriptor corePlugin = PluginManagerCore.getPlugin(PluginManagerCore.CORE_ID);
assert corePlugin != null;
WriteAction.runAndWait(() -> {
@@ -133,6 +138,15 @@ public class _LastInSuiteTest extends TestCase {
});
}
private static void finishCorePluginUnload() {
IdeaPluginDescriptor corePlugin = PluginManagerCore.getPlugin(PluginManagerCore.CORE_ID);
assert corePlugin != null;
WriteAction.runAndWait(() -> {
ApplicationManager.getApplication().getMessageBus().syncPublisher(DynamicPluginListener.TOPIC)
.pluginUnloaded(corePlugin, false);
});
}
@NotNull
private static Map<ExtensionPoint<?>, Collection<WeakReference<Object>>> collectDynamicNonPlatformExtensions() {
boolean useWhiteList = !SystemProperties.getBooleanProperty("intellij.test.all.dynamic.extension.points", false);