Handle the case of `Description` being null which is a valid case as described in the `HeartBeatEvent`'s javadoc, which previously resulted in exceptions that "pollute" the build output. Follows: #28563 Backport: #38799
This commit is contained in:
parent
36c274867e
commit
6181d2f4f4
|
@ -32,6 +32,7 @@ import com.carrotsearch.ant.tasks.junit4.events.aggregated.HeartBeatEvent
|
||||||
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
|
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
|
||||||
import org.gradle.internal.logging.progress.ProgressLogger
|
import org.gradle.internal.logging.progress.ProgressLogger
|
||||||
import org.gradle.internal.logging.progress.ProgressLoggerFactory
|
import org.gradle.internal.logging.progress.ProgressLoggerFactory
|
||||||
|
import org.junit.runner.Description
|
||||||
|
|
||||||
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
|
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
|
||||||
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.ERROR
|
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.ERROR
|
||||||
|
@ -113,7 +114,7 @@ class TestProgressLogger implements AggregatedEventListener {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
void onSuiteStart(AggregatedSuiteStartedEvent e) throws IOException {
|
void onSuiteStart(AggregatedSuiteStartedEvent e) throws IOException {
|
||||||
String suiteName = simpleName(e.suiteStartedEvent.description.className)
|
String suiteName = simpleName(e.suiteStartedEvent.description)
|
||||||
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${suiteName} - initializing")
|
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${suiteName} - initializing")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,31 +147,45 @@ class TestProgressLogger implements AggregatedEventListener {
|
||||||
throw new IllegalArgumentException("Unknown test status: [${e.status}]")
|
throw new IllegalArgumentException("Unknown test status: [${e.status}]")
|
||||||
}
|
}
|
||||||
testLogger.progress("Tests: completed: ${testsCompleted}, failed: ${testsFailed}, ignored: ${testsIgnored}")
|
testLogger.progress("Tests: completed: ${testsCompleted}, failed: ${testsFailed}, ignored: ${testsIgnored}")
|
||||||
String testName = simpleName(e.description.className) + '.' + e.description.methodName
|
String testName = testName(e.description)
|
||||||
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ${statusMessage}")
|
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ${statusMessage}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
void onTestStarted(TestStartedEvent e) throws IOException {
|
void onTestStarted(TestStartedEvent e) throws IOException {
|
||||||
String testName = simpleName(e.description.className) + '.' + e.description.methodName
|
String testName = testName(e.description)
|
||||||
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ...")
|
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ...")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
void onHeartbeat(HeartBeatEvent e) throws IOException {
|
void onHeartbeat(HeartBeatEvent e) throws IOException {
|
||||||
String testName = simpleName(e.description.className) + '.' + e.description.methodName
|
String testName = testName(e.description)
|
||||||
String time = formatDurationInSeconds(e.getNoEventDuration())
|
String time = formatDurationInSeconds(e.getNoEventDuration())
|
||||||
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} stalled for ${time}")
|
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} stalled for ${time}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the test name in the format of <className>.<methodName>
|
||||||
|
*/
|
||||||
|
private static String testName(Description description) {
|
||||||
|
String className = simpleName(description)
|
||||||
|
if (description == null) {
|
||||||
|
return className + "." + "<unknownMethod>"
|
||||||
|
}
|
||||||
|
return className + "." + description.methodName
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a Class#getSimpleName style name from Class#getName style
|
* Extract a Class#getSimpleName style name from Class#getName style
|
||||||
* string. We can't just use Class#getSimpleName because junit descriptions
|
* string. We can't just use Class#getSimpleName because junit descriptions
|
||||||
* don't always set the class field but they always set the className
|
* don't always set the class field but they always set the className
|
||||||
* field.
|
* field.
|
||||||
*/
|
*/
|
||||||
private static String simpleName(String className) {
|
private static String simpleName(Description description) {
|
||||||
return className.substring(className.lastIndexOf('.') + 1)
|
if (description == null) {
|
||||||
|
return "<unknownClass>"
|
||||||
|
}
|
||||||
|
return description.className.substring(description.className.lastIndexOf('.') + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue