test killability, take 2
authorpeter <peter@jetbrains.com>
Wed, 18 Jan 2012 19:29:08 +0000 (20:29 +0100)
committerpeter <peter@jetbrains.com>
Thu, 19 Jan 2012 16:53:26 +0000 (17:53 +0100)
platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java
platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java
platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java
platform/util/src/com/intellij/openapi/util/ShutDownTracker.java

index ced92a753e96862508bd3508c28d421a3815a4a4..a8262f35ff6c2a35ba303c0cabb6f0fd089d44eb 100644 (file)
@@ -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);
index 0743dafcb11efc347cb95a0ce4e5612903288d08..feeabc285a35e8582dd5426f58639448f5aecc41 100644 (file)
@@ -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 {
index 90d5833dd09d862dd63a31e2cc434c3d0d8f0842..3165c27634dcbd62dec33966ec42964919c7af07 100644 (file)
@@ -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() {
index b4b50d0e4cf4453b079ad40e6eb6f5e27cc39e22..8cee75fb6bc25dd2ef19967374eab469cc627d7d 100644 (file)
@@ -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();