Merge pull request #18172 from rjernst/vagrant_logging2
Tests: Delay starting progress loggers for vagrant until test is running
This commit is contained in:
commit
52cdac4256
|
@ -19,9 +19,11 @@
|
||||||
package org.elasticsearch.gradle.vagrant
|
package org.elasticsearch.gradle.vagrant
|
||||||
|
|
||||||
import com.carrotsearch.gradle.junit4.LoggingOutputStream
|
import com.carrotsearch.gradle.junit4.LoggingOutputStream
|
||||||
|
import groovy.transform.PackageScope
|
||||||
import org.gradle.api.GradleScriptException
|
import org.gradle.api.GradleScriptException
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.logging.ProgressLogger
|
import org.gradle.logging.ProgressLogger
|
||||||
|
import org.gradle.logging.ProgressLoggerFactory
|
||||||
|
|
||||||
import java.util.regex.Matcher
|
import java.util.regex.Matcher
|
||||||
|
|
||||||
|
@ -35,73 +37,77 @@ import java.util.regex.Matcher
|
||||||
* There is a Tap4j project but we can't use it because it wants to parse the
|
* There is a Tap4j project but we can't use it because it wants to parse the
|
||||||
* entire TAP stream at once and won't parse it stream-wise.
|
* entire TAP stream at once and won't parse it stream-wise.
|
||||||
*/
|
*/
|
||||||
class TapLoggerOutputStream extends LoggingOutputStream {
|
public class TapLoggerOutputStream extends LoggingOutputStream {
|
||||||
ProgressLogger progressLogger
|
private final ProgressLogger progressLogger
|
||||||
Logger logger
|
private boolean isStarted = false
|
||||||
int testsCompleted = 0
|
private final Logger logger
|
||||||
int testsFailed = 0
|
private int testsCompleted = 0
|
||||||
int testsSkipped = 0
|
private int testsFailed = 0
|
||||||
Integer testCount
|
private int testsSkipped = 0
|
||||||
String countsFormat
|
private Integer testCount
|
||||||
|
private String countsFormat
|
||||||
|
|
||||||
TapLoggerOutputStream(Map args) {
|
TapLoggerOutputStream(Map args) {
|
||||||
logger = args.logger
|
logger = args.logger
|
||||||
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
||||||
progressLogger.setDescription("TAP output for `$args.command`")
|
progressLogger.setDescription("TAP output for `${args.command}`")
|
||||||
progressLogger.started()
|
|
||||||
progressLogger.progress("Starting `$args.command`...")
|
|
||||||
}
|
|
||||||
|
|
||||||
void flush() {
|
|
||||||
if (end == start) return
|
|
||||||
line(new String(buffer, start, end - start))
|
|
||||||
start = end
|
|
||||||
}
|
|
||||||
|
|
||||||
void line(String line) {
|
|
||||||
// System.out.print "===> $line\n"
|
|
||||||
if (testCount == null) {
|
|
||||||
try {
|
|
||||||
testCount = line.split('\\.').last().toInteger()
|
|
||||||
def length = (testCount as String).length()
|
|
||||||
countsFormat = "%0${length}d"
|
|
||||||
countsFormat = "[$countsFormat|$countsFormat|$countsFormat/$countsFormat]"
|
|
||||||
return
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new GradleScriptException(
|
|
||||||
'Error parsing first line of TAP stream!!', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Matcher m = line =~ /(?<status>ok|not ok) \d+(?<skip> # skip (?<skipReason>\(.+\))?)? \[(?<suite>.+)\] (?<test>.+)/
|
|
||||||
if (!m.matches()) {
|
|
||||||
/* These might be failure report lines or comments or whatever. Its hard
|
|
||||||
to tell and it doesn't matter. */
|
|
||||||
logger.warn(line)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
boolean skipped = m.group('skip') != null
|
|
||||||
boolean success = !skipped && m.group('status') == 'ok'
|
|
||||||
String skipReason = m.group('skipReason')
|
|
||||||
String suiteName = m.group('suite')
|
|
||||||
String testName = m.group('test')
|
|
||||||
|
|
||||||
String status
|
|
||||||
if (skipped) {
|
|
||||||
status = "SKIPPED"
|
|
||||||
testsSkipped++
|
|
||||||
} else if (success) {
|
|
||||||
status = " OK"
|
|
||||||
testsCompleted++
|
|
||||||
} else {
|
|
||||||
status = " FAILED"
|
|
||||||
testsFailed++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String counts = sprintf(countsFormat,
|
@Override
|
||||||
[testsCompleted, testsFailed, testsSkipped, testCount])
|
public void flush() {
|
||||||
progressLogger.progress("Tests $counts, $status [$suiteName] $testName")
|
if (isStarted == false) {
|
||||||
if (!success) {
|
progressLogger.started()
|
||||||
logger.warn(line)
|
isStarted = true
|
||||||
|
}
|
||||||
|
if (end == start) return
|
||||||
|
line(new String(buffer, start, end - start))
|
||||||
|
start = end
|
||||||
|
}
|
||||||
|
|
||||||
|
void line(String line) {
|
||||||
|
// System.out.print "===> $line\n"
|
||||||
|
if (testCount == null) {
|
||||||
|
try {
|
||||||
|
testCount = line.split('\\.').last().toInteger()
|
||||||
|
def length = (testCount as String).length()
|
||||||
|
countsFormat = "%0${length}d"
|
||||||
|
countsFormat = "[$countsFormat|$countsFormat|$countsFormat/$countsFormat]"
|
||||||
|
return
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new GradleScriptException(
|
||||||
|
'Error parsing first line of TAP stream!!', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Matcher m = line =~ /(?<status>ok|not ok) \d+(?<skip> # skip (?<skipReason>\(.+\))?)? \[(?<suite>.+)\] (?<test>.+)/
|
||||||
|
if (!m.matches()) {
|
||||||
|
/* These might be failure report lines or comments or whatever. Its hard
|
||||||
|
to tell and it doesn't matter. */
|
||||||
|
logger.warn(line)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
boolean skipped = m.group('skip') != null
|
||||||
|
boolean success = !skipped && m.group('status') == 'ok'
|
||||||
|
String skipReason = m.group('skipReason')
|
||||||
|
String suiteName = m.group('suite')
|
||||||
|
String testName = m.group('test')
|
||||||
|
|
||||||
|
String status
|
||||||
|
if (skipped) {
|
||||||
|
status = "SKIPPED"
|
||||||
|
testsSkipped++
|
||||||
|
} else if (success) {
|
||||||
|
status = " OK"
|
||||||
|
testsCompleted++
|
||||||
|
} else {
|
||||||
|
status = " FAILED"
|
||||||
|
testsFailed++
|
||||||
|
}
|
||||||
|
|
||||||
|
String counts = sprintf(countsFormat,
|
||||||
|
[testsCompleted, testsFailed, testsSkipped, testCount])
|
||||||
|
progressLogger.progress("Tests $counts, $status [$suiteName] $testName")
|
||||||
|
if (!success) {
|
||||||
|
logger.warn(line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.elasticsearch.gradle.vagrant
|
package org.elasticsearch.gradle.vagrant
|
||||||
|
|
||||||
import com.carrotsearch.gradle.junit4.LoggingOutputStream
|
import com.carrotsearch.gradle.junit4.LoggingOutputStream
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.logging.ProgressLogger
|
import org.gradle.logging.ProgressLogger
|
||||||
import org.gradle.logging.ProgressLoggerFactory
|
import org.gradle.logging.ProgressLoggerFactory
|
||||||
|
|
||||||
|
@ -46,31 +47,31 @@ import org.gradle.logging.ProgressLoggerFactory
|
||||||
public class VagrantLoggerOutputStream extends LoggingOutputStream {
|
public class VagrantLoggerOutputStream extends LoggingOutputStream {
|
||||||
private static final String HEADING_PREFIX = '==> '
|
private static final String HEADING_PREFIX = '==> '
|
||||||
|
|
||||||
ProgressLoggerFactory progressLoggerFactory
|
private final ProgressLogger progressLogger
|
||||||
|
private boolean isStarted = false
|
||||||
|
private String squashedPrefix
|
||||||
private ProgressLogger progressLogger
|
private String lastLine = ''
|
||||||
String squashedPrefix
|
private boolean inProgressReport = false
|
||||||
String lastLine = ''
|
private String heading = ''
|
||||||
boolean inProgressReport = false
|
|
||||||
String heading = ''
|
|
||||||
|
|
||||||
VagrantLoggerOutputStream(Map args) {
|
VagrantLoggerOutputStream(Map args) {
|
||||||
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
progressLogger = args.factory.newOperation(VagrantLoggerOutputStream)
|
||||||
progressLogger.setDescription("Vagrant output for `$args.command`")
|
progressLogger.setDescription("Vagrant output for `$args.command`")
|
||||||
progressLogger.started()
|
|
||||||
progressLogger.progress("Starting `$args.command`...")
|
|
||||||
squashedPrefix = args.squashedPrefix
|
squashedPrefix = args.squashedPrefix
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush() {
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
if (isStarted == false) {
|
||||||
|
progressLogger.started()
|
||||||
|
isStarted = true
|
||||||
|
}
|
||||||
if (end == start) return
|
if (end == start) return
|
||||||
line(new String(buffer, start, end - start))
|
line(new String(buffer, start, end - start))
|
||||||
start = end
|
start = end
|
||||||
}
|
}
|
||||||
|
|
||||||
void line(String line) {
|
void line(String line) {
|
||||||
// debugPrintLine(line) // Uncomment me to log every incoming line
|
|
||||||
if (line.startsWith('\r\u001b')) {
|
if (line.startsWith('\r\u001b')) {
|
||||||
/* We don't want to try to be a full terminal emulator but we want to
|
/* We don't want to try to be a full terminal emulator but we want to
|
||||||
keep the escape sequences from leaking and catch _some_ of the
|
keep the escape sequences from leaking and catch _some_ of the
|
||||||
|
@ -97,28 +98,6 @@ public class VagrantLoggerOutputStream extends LoggingOutputStream {
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// debugLogLine(line) // Uncomment me to log every line we add to the logger
|
|
||||||
progressLogger.progress(line)
|
progressLogger.progress(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
void debugPrintLine(line) {
|
|
||||||
System.out.print '----------> '
|
|
||||||
for (int i = start; i < end; i++) {
|
|
||||||
switch (buffer[i] as char) {
|
|
||||||
case ' '..'~':
|
|
||||||
System.out.print buffer[i] as char
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
System.out.print '%'
|
|
||||||
System.out.print Integer.toHexString(buffer[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.print '\n'
|
|
||||||
}
|
|
||||||
|
|
||||||
void debugLogLine(line) {
|
|
||||||
System.out.print '>>>>>>>>>>> '
|
|
||||||
System.out.print line
|
|
||||||
System.out.print '\n'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue