mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
removed mock application thread pool from tests
This commit is contained in:
+21
-8
@@ -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<StructureElement> 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<Object> 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<StructureElement> extends FlyIdeaTestCase {
|
||||
|
||||
return ready[0];
|
||||
}
|
||||
}.isConditionRealized();
|
||||
});
|
||||
|
||||
if (myCancelRequest != null) {
|
||||
throw new Exception(myCancelRequest);
|
||||
@@ -355,12 +368,12 @@ abstract class BaseTreeTestCase<StructureElement> 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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user