FlakyTestLogger for debugging the SpringIntentionsTest

GitOrigin-RevId: 1130715be3508cbaab8579dbbc8193e5713dfa9d
This commit is contained in:
Nicolay Mitropolsky
2021-05-14 15:11:37 +03:00
committed by intellij-monorepo-bot
parent 29d96a1e9d
commit 5ebc371a20
3 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testFramework
import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.Key
import org.jetbrains.annotations.TestOnly
import java.io.PrintWriter
import java.io.StringWriter
@Deprecated("this class is here only for debugging a flaky test, it will be deleted as soon problem will be resolved")
class FlakyTestLogger(val enabled: Boolean) : Disposable {
private val lines = ArrayList<String>()
override fun dispose() {
lines.forEach(System.out::println)
}
fun append(line: String) {
if (!enabled) return
lines.add(line)
}
fun append(exception: Exception) {
if (!enabled) return
val stringWriter = StringWriter()
exception.printStackTrace(PrintWriter(stringWriter))
lines.add(stringWriter.toString())
}
companion object {
private val KEY = Key.create<FlakyTestLogger>("LogAccumulator")
@JvmStatic
fun get(): FlakyTestLogger? = TestModeFlags.get(KEY)
@JvmStatic
fun force(): FlakyTestLogger = get() ?: FlakyTestLogger(false)
@JvmStatic
fun isEnabled(): Boolean = TestModeFlags.get(KEY) != null
@JvmStatic
@TestOnly
fun enable(disposer: Disposable) {
TestModeFlags.set(KEY, FlakyTestLogger(true).also { Disposer.register(disposer, it) }, disposer)
}
}
}

View File

@@ -20,6 +20,7 @@ import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.testFramework.FlakyTestLogger;
import com.intellij.util.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xml.*;
@@ -655,7 +656,17 @@ public abstract class DomInvocationHandler extends UserDataHolderBase implements
@Nullable
public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
return findInvocation(method).invoke(this, args);
Invocation invocation = findInvocation(method);
Object r = invocation.invoke(this, args);
FlakyTestLogger log = FlakyTestLogger.get();
if (log != null && method.getName().equals("exists")) {
log.append("Invocation: for '" + method + "' is '" + invocation + " of " + invocation.getClass() + "' handler = '" + this +
" of " + this.getClass() + "' r = " + r + " of " + ObjectUtils.doIfNotNull(r, Object::getClass));
if (this instanceof IndexedElementInvocationHandler) {
log.append(((IndexedElementInvocationHandler)this).created);
}
}
return r;
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();

View File

@@ -20,6 +20,7 @@ import com.intellij.openapi.util.Factory;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.testFramework.FlakyTestLogger;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.EvaluatedXmlName;
@@ -38,6 +39,8 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler {
private static final Logger LOG = Logger.getInstance(IndexedElementInvocationHandler.class);
private final int myIndex;
public final Exception created;
public IndexedElementInvocationHandler(final EvaluatedXmlName tagName,
final FixedChildDescriptionImpl description,
final int index,
@@ -45,6 +48,8 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler {
final DomManagerImpl manager,
@Nullable ElementStub stub) {
super(description.getType(), strategy, tagName, description, manager, strategy.isPhysical(), stub);
created = FlakyTestLogger.isEnabled() ? new Exception(
"IndexedElementInvocationHandler(" + tagName + ", " + description + ", " + strategy + ", " + index + ", " + stub + ")") : null;
myIndex = index;
}