test killability, take 2

This commit is contained in:
peter
2012-01-19 17:53:26 +01:00
parent b8c404890b
commit 99c8229516
4 changed files with 28 additions and 4 deletions
@@ -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);
@@ -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 {
@@ -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() {
@@ -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();