From a3215cb826ff88968b2f5e5d59151df49b74d403 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 8 Sep 2014 14:22:00 +0400 Subject: [PATCH] removed mock application thread pool from tests --- .../ide/util/treeView/BaseTreeTestCase.java | 29 ++++++++++----- .../ide/util/treeView/TreeUiTest.java | 19 +++++----- .../testFramework/FlyIdeaTestCase.java | 35 +++++++++---------- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/BaseTreeTestCase.java b/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/BaseTreeTestCase.java index fc5c5edec615..0ce7aef30038 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/BaseTreeTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/BaseTreeTestCase.java @@ -15,11 +15,14 @@ */ package com.intellij.ide.util.treeView; -import com.intellij.openapi.util.*; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Conditions; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.SimpleTimer; import com.intellij.testFramework.FlyIdeaTestCase; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.WaitFor; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.ComparableObject; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -94,10 +97,20 @@ abstract class BaseTreeTestCase extends FlyIdeaTestCase { } } + protected static boolean waitFor(int timeoutMs, @NotNull Condition condition) { + boolean isDispatchThread = ApplicationManager.getApplication().isDispatchThread(); + long start = System.currentTimeMillis(); + while (System.currentTimeMillis() - start < timeoutMs) { + if (condition.value(null)) return true; + if (isDispatchThread) UIUtil.dispatchAllInvocationEvents(); + } + return false; + } + void waitBuilderToCome(final Condition condition) throws Exception { - boolean success = new WaitFor(60000) { + boolean success = waitFor(60000, new Condition() { @Override - protected boolean condition() { + public boolean value(Object o) { final boolean[] ready = {false}; invokeAndWaitIfNeeded(new Runnable() { @Override @@ -114,7 +127,7 @@ abstract class BaseTreeTestCase extends FlyIdeaTestCase { return ready[0]; } - }.isConditionRealized(); + }); if (myCancelRequest != null) { throw new Exception(myCancelRequest); @@ -355,12 +368,12 @@ abstract class BaseTreeTestCase extends FlyIdeaTestCase { } }); - new WaitFor(6000) { + waitFor(6000, new Condition() { @Override - protected boolean condition() { + public boolean value(Object o) { return getBuilder() == null || getBuilder().getUi() == null; } - }; + }); super.tearDown(); } diff --git a/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java b/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java index 99c6f5b5d25a..b98d7e7c78e4 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/util/treeView/TreeUiTest.java @@ -21,7 +21,6 @@ import com.intellij.openapi.progress.Progressive; import com.intellij.openapi.util.*; import com.intellij.ui.LoadingNode; import com.intellij.util.Time; -import com.intellij.util.WaitFor; import com.intellij.util.ui.UIUtil; import junit.framework.AssertionFailedError; import junit.framework.TestSuite; @@ -1063,12 +1062,12 @@ public class TreeUiTest extends AbstractTreeBuilderTest { } }); - new WaitFor(60000) { + waitFor(60000, new Condition() { @Override - protected boolean condition() { + public boolean value(Object o) { return done[0] && getMyBuilder().getUi().isReady(); } - }; + }); assertTrue(done[0]); assertEquals(1, notifyCount[0]); @@ -1357,12 +1356,12 @@ public class TreeUiTest extends AbstractTreeBuilderTest { } }); - new WaitFor() { + waitFor(60000, new Condition() { @Override - protected boolean condition() { + public boolean value(Object o) { return queued.get(); } - }; + }); assertTrue(getBuilder().getUi().isIdle()); assertTreeNow("+null\n"); @@ -2570,12 +2569,12 @@ public class TreeUiTest extends AbstractTreeBuilderTest { buildAction.run(); - boolean released = new WaitFor(15000) { + boolean released = waitFor(15000, new Condition() { @Override - protected boolean condition() { + public boolean value(Object o) { return getBuilder().getUi() == null; } - }.isConditionRealized(); + }); assertTrue(released); } diff --git a/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java b/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java index 02a39f148e24..098d76599f5b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/FlyIdeaTestCase.java @@ -1,36 +1,35 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.testFramework; -import com.intellij.mock.MockApplicationEx; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; import junit.framework.TestCase; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; -import java.util.concurrent.Future; public abstract class FlyIdeaTestCase extends TestCase { - - private Disposable myRootDisposable; + private final Disposable myRootDisposable = Disposer.newDisposable(); private File myTempDir; @Override protected void setUp() throws Exception { - final Application old = ApplicationManagerEx.getApplication(); - myRootDisposable = Disposer.newDisposable(); - MockApplicationEx app = new MockApplicationEx(getRootDisposable()) { - @NotNull - @Override - public Future executeOnPooledThread(@NotNull Runnable action) { - return old != null ? old.executeOnPooledThread(action) : super.executeOnPooledThread(action); - } - }; - ApplicationManager.setApplication(app, myRootDisposable); + LightPlatformTestCase.initApplication(); } public File getTempDir() throws IOException {