From 2d2b232a7d7ddafc830b4e7dbf3c0398da4a50eb Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 5 May 2016 16:08:51 -0700 Subject: [PATCH] Tests: Delay starting progress loggers for vagrant until test is running This was broken recently as part of making the vagrant tasks extend LoggedExec. This change fixes the progress logger to not be started until we start seeing output from vagrant. --- .../vagrant/TapLoggerOutputStream.groovy | 136 +++++++++--------- .../vagrant/VagrantLoggerOutputStream.groovy | 47 ++---- 2 files changed, 84 insertions(+), 99 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy index 6b87ceeaf96..3f980c57a49 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy @@ -19,9 +19,11 @@ package org.elasticsearch.gradle.vagrant import com.carrotsearch.gradle.junit4.LoggingOutputStream +import groovy.transform.PackageScope import org.gradle.api.GradleScriptException import org.gradle.api.logging.Logger import org.gradle.logging.ProgressLogger +import org.gradle.logging.ProgressLoggerFactory 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 * entire TAP stream at once and won't parse it stream-wise. */ -class TapLoggerOutputStream extends LoggingOutputStream { - ProgressLogger progressLogger - Logger logger - int testsCompleted = 0 - int testsFailed = 0 - int testsSkipped = 0 - Integer testCount - String countsFormat +public class TapLoggerOutputStream extends LoggingOutputStream { + private final ProgressLogger progressLogger + private boolean isStarted = false + private final Logger logger + private int testsCompleted = 0 + private int testsFailed = 0 + private int testsSkipped = 0 + private Integer testCount + private String countsFormat - TapLoggerOutputStream(Map args) { - logger = args.logger - progressLogger = args.factory.newOperation(VagrantLoggerOutputStream) - 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 =~ /(?ok|not ok) \d+(? # skip (?\(.+\))?)? \[(?.+)\] (?.+)/ - 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++ + TapLoggerOutputStream(Map args) { + logger = args.logger + progressLogger = args.factory.newOperation(VagrantLoggerOutputStream) + progressLogger.setDescription("TAP output for `${args.command}`") } - String counts = sprintf(countsFormat, - [testsCompleted, testsFailed, testsSkipped, testCount]) - progressLogger.progress("Tests $counts, $status [$suiteName] $testName") - if (!success) { - logger.warn(line) + @Override + public void flush() { + if (isStarted == false) { + progressLogger.started() + 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 =~ /(?ok|not ok) \d+(? # skip (?\(.+\))?)? \[(?.+)\] (?.+)/ + 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) + } } - } } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy index 22008fa1a0e..331a638b5ca 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy @@ -19,6 +19,7 @@ package org.elasticsearch.gradle.vagrant import com.carrotsearch.gradle.junit4.LoggingOutputStream +import org.gradle.api.logging.Logger import org.gradle.logging.ProgressLogger import org.gradle.logging.ProgressLoggerFactory @@ -46,31 +47,31 @@ import org.gradle.logging.ProgressLoggerFactory public class VagrantLoggerOutputStream extends LoggingOutputStream { private static final String HEADING_PREFIX = '==> ' - ProgressLoggerFactory progressLoggerFactory - - - private ProgressLogger progressLogger - String squashedPrefix - String lastLine = '' - boolean inProgressReport = false - String heading = '' + private final ProgressLogger progressLogger + private boolean isStarted = false + private String squashedPrefix + private String lastLine = '' + private boolean inProgressReport = false + private String heading = '' VagrantLoggerOutputStream(Map args) { progressLogger = args.factory.newOperation(VagrantLoggerOutputStream) progressLogger.setDescription("Vagrant output for `$args.command`") - progressLogger.started() - progressLogger.progress("Starting `$args.command`...") squashedPrefix = args.squashedPrefix } - void flush() { + @Override + public void flush() { + if (isStarted == false) { + progressLogger.started() + isStarted = true + } if (end == start) return line(new String(buffer, start, end - start)) start = end } void line(String line) { - // debugPrintLine(line) // Uncomment me to log every incoming line if (line.startsWith('\r\u001b')) { /* 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 @@ -97,28 +98,6 @@ public class VagrantLoggerOutputStream extends LoggingOutputStream { } else { return } - // debugLogLine(line) // Uncomment me to log every line we add to the logger 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' - } }