Search in sources :

Example 6 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class ThreadTracker method checkLeak.

@TestOnly
public void checkLeak() throws AssertionError {
    NettyUtil.awaitQuiescenceOfGlobalEventExecutor(100, TimeUnit.SECONDS);
    ShutDownTracker.getInstance().waitFor(100, TimeUnit.SECONDS);
    try {
        if (myDefaultProjectInitialized != ((ProjectManagerImpl) ProjectManager.getInstance()).isDefaultProjectInitialized())
            return;
        Collection<Thread> after = new THashSet<>(getThreads());
        after.removeAll(before);
        for (final Thread thread : after) {
            if (thread == Thread.currentThread())
                continue;
            ThreadGroup group = thread.getThreadGroup();
            if (group != null && "system".equals(group.getName()))
                continue;
            if (isWellKnownOffender(thread))
                continue;
            if (!thread.isAlive())
                continue;
            if (thread.getStackTrace().length == 0) {
                thread.interrupt();
                if (new WaitFor(10000) {

                    @Override
                    protected boolean condition() {
                        return !thread.isAlive();
                    }
                }.isConditionRealized()) {
                    continue;
                }
            }
            StackTraceElement[] stackTrace = thread.getStackTrace();
            if (stackTrace.length == 0) {
                // ignore threads with empty stack traces for now. Seems they are zombies unwilling to die.
                continue;
            }
            if (isIdleApplicationPoolThread(thread, stackTrace)) {
                continue;
            }
            @SuppressWarnings("NonConstantStringShouldBeStringBuffer") String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
            for (final StackTraceElement stackTraceElement : stackTrace) {
                trace += " at " + stackTraceElement + "\n";
            }
            trace += "---\n";
            Assert.fail(trace);
        }
    } finally {
        before.clear();
    }
}
Also used : WaitFor(com.intellij.util.WaitFor) THashSet(gnu.trove.THashSet) TestOnly(org.jetbrains.annotations.TestOnly)

Example 7 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class AbstractTreeBuilderTest method hideTree.

void hideTree() throws Exception {
    Assert.assertFalse(getMyBuilder().myWasCleanedUp);
    invokeLaterIfNeeded(() -> getBuilder().getUi().deactivate());
    final WaitFor waitFor = new WaitFor() {

        @Override
        protected boolean condition() {
            return getMyBuilder().myWasCleanedUp || myCancelRequest != null;
        }
    };
    if (myCancelRequest != null) {
        throw new Exception(myCancelRequest);
    }
    waitFor.assertCompleted("Tree cleanup was not performed. isCancelledReadyState=" + getBuilder().getUi().isCancelledReady());
    Assert.assertTrue(getMyBuilder().myWasCleanedUp);
}
Also used : WaitFor(com.intellij.util.WaitFor)

Example 8 with WaitFor

use of com.intellij.util.WaitFor in project intellij-community by JetBrains.

the class BaseTreeTestCase method waitBuilderToCome.

void waitBuilderToCome(final Condition<Object> condition) throws Exception {
    boolean success = new WaitFor(60000) {

        @Override
        protected boolean condition() {
            final boolean[] ready = { false };
            invokeAndWaitIfNeeded(() -> {
                AbstractTreeUi ui = getBuilder().getUi();
                if (ui == null) {
                    ready[0] = true;
                    return;
                }
                ready[0] = myCancelRequest != null || myReadyRequest || condition.value(null) && ui.isReady();
            });
            return ready[0];
        }
    }.isConditionRealized();
    if (myCancelRequest != null) {
        throw new Exception(myCancelRequest);
    }
    if (!myReadyRequest) {
        if (!getBuilder().isDisposed()) {
            Assert.assertEquals("{}", getBuilder().getUi().getNodeActions().toString());
        }
    }
    Assert.assertTrue(success);
}
Also used : WaitFor(com.intellij.util.WaitFor)

Aggregations

WaitFor (com.intellij.util.WaitFor)8 PlaybackRunner (com.intellij.openapi.ui.playback.PlaybackRunner)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 IOException (java.io.IOException)1 TestOnly (org.jetbrains.annotations.TestOnly)1