From af7dd1def7e9f094b9651d327f702d054c17ee01 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 7 Feb 2017 09:47:25 +0100 Subject: [PATCH] ensure project leak hunter is started (when first test which init the app is UsefulTestCase, then initial val of ourDebugMode is false and it would be restored in tearDown, afterwards only explicit setting to true would help) --- .../openapi/application/impl/ApplicationImpl.java | 3 +-- .../testframework/sm/runner/BaseSMTRunnerTestCase.java | 8 ++++++++ platform/testFramework/src/_LastInSuiteTest.java | 6 ++++++ .../src/com/intellij/testFramework/UsefulTestCase.java | 3 +-- .../util/src/com/intellij/openapi/util/Disposer.java | 10 +++++++++- 5 files changed, 25 insertions(+), 5 deletions(-) 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 144e58a2b560..7e6b0c7221a1 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 @@ -163,8 +163,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App AWTExceptionHandler.register(); // do not crash AWT on exceptions - String debugDisposer = System.getProperty("idea.disposer.debug"); - Disposer.setDebugMode((isInternal || isUnitTestMode || "on".equals(debugDisposer)) && !"off".equals(debugDisposer)); + Disposer.setDebugMode((isInternal || isUnitTestMode || Disposer.isDebugDisposerOn())); myStartTime = System.currentTimeMillis(); mySplash = splash; diff --git a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/BaseSMTRunnerTestCase.java b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/BaseSMTRunnerTestCase.java index 734e59f044a5..b90bf5beb882 100644 --- a/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/BaseSMTRunnerTestCase.java +++ b/platform/smRunner/testSrc/com/intellij/execution/testframework/sm/runner/BaseSMTRunnerTestCase.java @@ -18,6 +18,7 @@ package com.intellij.execution.testframework.sm.runner; import com.intellij.execution.configurations.ModuleRunConfiguration; import com.intellij.execution.executors.DefaultDebugExecutor; import com.intellij.execution.testframework.TestConsoleProperties; +import com.intellij.openapi.util.Disposer; import com.intellij.testFramework.LightPlatformTestCase; /** @@ -35,6 +36,13 @@ public abstract class BaseSMTRunnerTestCase extends LightPlatformTestCase { mySimpleTest = createTestProxy(); } + @Override + protected void tearDown() throws Exception { + if (mySuite != null) Disposer.dispose(mySuite); + if (mySimpleTest != null) Disposer.dispose(mySimpleTest); + super.tearDown(); + } + protected SMTestProxy createTestProxy() { return createTestProxy("test"); } diff --git a/platform/testFramework/src/_LastInSuiteTest.java b/platform/testFramework/src/_LastInSuiteTest.java index 0647c9eccf27..f0e29d0b8f43 100644 --- a/platform/testFramework/src/_LastInSuiteTest.java +++ b/platform/testFramework/src/_LastInSuiteTest.java @@ -42,6 +42,12 @@ import java.util.concurrent.TimeUnit; */ @SuppressWarnings("JUnitTestClassNamingConvention") public class _LastInSuiteTest extends TestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + Disposer.setDebugMode(true); + } + public void testProjectLeak() throws Exception { boolean guiTestMode = Boolean.getBoolean("idea.test.guimode"); if (guiTestMode) { diff --git a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java index e843cfa536c5..c0bf9c248307 100644 --- a/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java @@ -147,7 +147,7 @@ public abstract class UsefulTestCase extends TestCase { boolean isStressTest = isStressTest(); ApplicationInfoImpl.setInStressTest(isStressTest); // turn off Disposer debugging for performance tests - oldDisposerDebug = Disposer.setDebugMode(Disposer.isDebugMode() && !isStressTest); + Disposer.setDebugMode(!isStressTest); } @Override @@ -158,7 +158,6 @@ public abstract class UsefulTestCase extends TestCase { cleanupDeleteOnExitHookList(); } finally { - Disposer.setDebugMode(oldDisposerDebug); if (shouldContainTempFiles()) { FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR); if (hasTmpFilesToKeep()) { diff --git a/platform/util/src/com/intellij/openapi/util/Disposer.java b/platform/util/src/com/intellij/openapi/util/Disposer.java index 90f69172eecc..ff637f536966 100644 --- a/platform/util/src/com/intellij/openapi/util/Disposer.java +++ b/platform/util/src/com/intellij/openapi/util/Disposer.java @@ -56,6 +56,11 @@ public class Disposer { } }; + private static String debugDisposer = System.getProperty("idea.disposer.debug"); + public static boolean isDebugDisposerOn() { + return "on".equals(debugDisposer); + } + private static boolean ourDebugMode; private Disposer() { @@ -144,7 +149,10 @@ public class Disposer { /** * @return old value */ - public static boolean setDebugMode(final boolean debugMode) { + public static boolean setDebugMode(boolean debugMode) { + if (debugMode) { + debugMode = !"off".equals(debugDisposer); + } boolean oldValue = ourDebugMode; ourDebugMode = debugMode; return oldValue;