You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2019/12/08 20:50:08 UTC

[lucene-solr] 01/04: Add some support for -Ptests.verbose mode when streams are dumped to the console. This is constrained by gradle's runner but is better than nothing.

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch gradle-master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 1021f04d1a7c4176d6ff0d437266f4c3fd9c1c4d
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Sat Dec 7 14:53:13 2019 +0100

    Add some support for -Ptests.verbose mode when streams are dumped to the console. This is constrained by gradle's runner but is better than nothing.
---
 gradle/testing/defaults-tests.gradle   | 56 ++++++++++++++++++++++++++++------
 gradle/testing/fail-on-no-tests.gradle |  6 +++-
 help/tests.txt                         | 14 ++++-----
 3 files changed, 58 insertions(+), 18 deletions(-)

diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index c454b5c..3dcf76c 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -1,8 +1,12 @@
 import org.apache.tools.ant.taskdefs.condition.Os
 import org.gradle.api.tasks.testing.logging.*
 
+def verboseModeHookInstalled = false
+
 allprojects {
   plugins.withType(JavaPlugin) {
+    def verboseMode = propertyOrDefault("tests.verbose", "false")
+
     project.ext {
       testsWorkDir = file("${buildDir}/tmp/tests-cwd")
       testsTmpDir = file("${buildDir}/tmp/tests-tmp")
@@ -10,13 +14,33 @@ allprojects {
       commonSolrDir = project(":solr").projectDir
     }
 
+    // If we're running in verbose mode and:
+    // 1) worker count > 1
+    // 2) number of 'test' tasks in the build is > 1
+    // then the output would very likely be mangled on the
+    // console. Fail and let the user know what to do.
+    if (verboseMode && !verboseModeHookInstalled) {
+      verboseModeHookInstalled = true
+      if (gradle.startParameter.maxWorkerCount > 1) {
+        gradle.taskGraph.whenReady { graph ->
+          def testTasks = graph.allTasks.findAll { task -> task instanceof Test }
+          if (testTasks.size() > 1) {
+            throw new GradleException("Run your tests in verbose mode only with --max-workers=1 option passed to gradle.")
+          }
+        }
+      }
+    }
+
     test {
-      workingDir testsWorkDir
+      if (verboseMode) {
+        maxParallelForks = 1
+      } else {
+        maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))
+      }
 
+      workingDir testsWorkDir
       useJUnit()
 
-      maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))
-
       minHeapSize = "256m"
       maxHeapSize = "512m"
 
@@ -44,12 +68,26 @@ allprojects {
       }
 
       // Set up logging.
-      testLogging {
-        events TestLogEvent.FAILED
-        exceptionFormat TestExceptionFormat.FULL
-        showExceptions true
-        showCauses true
-        showStackTraces true
+      if (verboseMode) {
+        testLogging {
+          events TestLogEvent.FAILED
+          exceptionFormat TestExceptionFormat.FULL
+          showExceptions true
+          showCauses true
+          showStackTraces true
+          showStandardStreams = false
+        }
+        onOutput { td, event ->
+          print event.message
+        }
+      } else {
+        testLogging {
+          events TestLogEvent.FAILED
+          exceptionFormat TestExceptionFormat.FULL
+          showExceptions true
+          showCauses true
+          showStackTraces true
+        }
       }
 
       doFirst {
diff --git a/gradle/testing/fail-on-no-tests.gradle b/gradle/testing/fail-on-no-tests.gradle
index dd148d1..f037725 100644
--- a/gradle/testing/fail-on-no-tests.gradle
+++ b/gradle/testing/fail-on-no-tests.gradle
@@ -22,8 +22,12 @@ gradle.taskGraph.whenReady { graph ->
     // ... and there are some test tasks in the execution graph.
     if (!testTasks.isEmpty()) {
       def executedTests = 0
+      def executedTasks = 0
 
       testTasks.each { task ->
+        task.doFirst {
+          executedTasks++
+        }
         task.afterSuite { desc, result ->
           executedTests += result.testCount
         }
@@ -31,7 +35,7 @@ gradle.taskGraph.whenReady { graph ->
 
       // After the build is finished, check the test count.
       gradle.buildFinished {
-        if (executedTests == 0) {
+        if (executedTests == 0 && executedTasks > 0) {
           throw new GradleException("No tests found for the given filters?")
         }
       }
diff --git a/help/tests.txt b/help/tests.txt
index 686113e..09d8c35 100644
--- a/help/tests.txt
+++ b/help/tests.txt
@@ -94,13 +94,11 @@ cleanTest task:
 gradlew -p lucene/core cleanTest test -Ptests.seed=deadbeef
 
 
+Verbose mode and debugging
+--------------------------
 
+The "tests.verbose" mode switch enables standard streams from tests
+to be dumped directly to the console. Run your verbose tests explicitly
+specifying the project and test task or a fully qualified task path. Example:
 
-
-
-
-
-
-
-
-
+gradlew -p lucene/core test -Ptests.verbose=true --tests "TestDemo"