diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index ced92a753e96..a8262f35ff6c 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -316,7 +316,12 @@ public class FileBasedIndex implements ApplicationComponent { ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { @Override public void run() { - performShutdown(); + ShutDownTracker.invokeAndWait(ApplicationManager.getApplication().isUnitTestMode(), false, new Runnable() { + @Override + public void run() { + performShutdown(); + } + }); } }); //FileUtil.createIfDoesntExist(workInProgressFile); diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 0743dafcb11e..feeabc285a35 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -285,7 +285,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application if (isDisposed() || isDisposeInProgress()) { return; } - ShutDownTracker.invokeAndWait(isUnitTestMode(), new Runnable() { + ShutDownTracker.invokeAndWait(isUnitTestMode(), true, new Runnable() { public void run() { if (ApplicationManager.getApplication() != ApplicationImpl.this) return; try { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 90d5833dd09d..3165c27634dc 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -735,7 +735,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da ShutDownTracker.getInstance().registerShutdownTask(new Runnable() { @Override public void run() { - ShutDownTracker.invokeAndWait(true, new Runnable() { + ShutDownTracker.invokeAndWait(true, true, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { diff --git a/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java b/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java index b4b50d0e4cf4..8cee75fb6bc2 100644 --- a/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java +++ b/platform/util/src/com/intellij/openapi/util/ShutDownTracker.java @@ -133,7 +133,26 @@ public class ShutDownTracker implements Runnable { return list.isEmpty()? null : list.removeLast(); } - public static void invokeAndWait(boolean timed, final Runnable runnable) { + public static void invokeAndWait(boolean timed, boolean edt, final Runnable runnable) { + if (!edt) { + if (!timed) { + runnable.run(); + } + + final Semaphore semaphore = new Semaphore(); + semaphore.down(); + new Thread(new Runnable() { + @Override + public void run() { + runnable.run(); + semaphore.up(); + } + }).start(); + semaphore.waitFor(1000); + + return; + } + if (timed) { final Semaphore semaphore = new Semaphore(); semaphore.down();