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();
}
}
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);
}
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);
}
Aggregations