You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/23 20:16:20 UTC

[tomcat] branch 7.0.x updated: Enable parallel execution of unit tests

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

markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new 5c44567  Enable parallel execution of unit tests
5c44567 is described below

commit 5c44567a6483ea46e68798107e27f7e07febdcb7
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jul 23 21:16:05 2019 +0100

    Enable parallel execution of unit tests
---
 build.properties.default                           |  6 ++++
 build.xml                                          | 36 +++++++++++++++++++---
 .../apache/catalina/startup/LoggingBaseTest.java   |  9 ++++--
 webapps/docs/changelog.xml                         |  7 +++++
 4 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/build.properties.default b/build.properties.default
index 68bfa21..93296a2 100644
--- a/build.properties.default
+++ b/build.properties.default
@@ -43,6 +43,12 @@ test.accesslog=false
 # Display the tests output on the console
 test.verbose=true
 
+# Number of parallel threads to use for testing. The recommended value is one
+# thread per core.
+# Note: Cobertura code coverage currently requires this to be set to 1. Setting
+#       a value above one will disable code coverage if enabled.
+test.threads=1
+
 # Note the Cobertura code coverage tool is GPLv2 licensed
 test.cobertura=false
 
diff --git a/build.xml b/build.xml
index 9e8d537..1e40448 100644
--- a/build.xml
+++ b/build.xml
@@ -1470,7 +1470,8 @@
         errorproperty="test.result.error"
         failureproperty="test.result.failure"
         haltonfailure="${test.haltonfailure}"
-        jvm="${java.bin.path}java" >
+        jvm="${java.bin.path}java"
+        threads="${test.threads}">
 
         <jvmarg value="${test.jvmarg.egd}"/>
         <jvmarg value="-Djava.library.path=${test.apr.loc}"/>
@@ -1522,15 +1523,39 @@
     </sequential>
   </macrodef>
 
-  <target name="cobertura-disabled" unless="${test.cobertura}">
+  <target name="cobertura-init">
+    <condition property="cobertura.enabled" value="true">
+      <and>
+        <istrue value="${test.cobertura}"/>
+        <equals arg1="1" arg2="${test.threads}"/>
+      </and>
+    </condition>
+    <condition property="cobertura.disabled" value="true">
+      <and>
+        <istrue value="${test.cobertura}"/>
+        <not>
+          <equals arg1="1" arg2="${test.threads}"/>
+        </not>
+      </and>
+    </condition>
+  </target>
+
+  <target name="cobertura-disabled" unless="${cobertura.enabled}"
+          depends="cobertura-init">
     <!-- Define classpath used to run tests when Cobertura is turned off. -->
     <path id="tomcat.test.run.classpath">
       <path refid="tomcat.test.classpath" />
     </path>
   </target>
 
-  <target name="cobertura-instrument" depends="compile,download-cobertura,cobertura-disabled"
-          if="${test.cobertura}"
+  <target name="cobertura-disabled-log" if="${cobertura.disabled}"
+          depends="cobertura-init">
+    <echo message="Code coverage disabled because test.threads is greater than 1"/>
+  </target>
+
+  <target name="cobertura-instrument"
+          depends="compile,download-cobertura,cobertura-disabled,cobertura-disabled-log"
+          if="${cobertura.enabled}"
           description="Adds Cobertura instrumentation to the compiled bytecode">
 
     <path id="cobertura.classpath">
@@ -1540,6 +1565,7 @@
         <exclude name="lib/**/jetty*.jar" />
         <exclude name="lib/**/servlet-api*.jar" />
       </fileset>
+      <pathelement path="res/cobertura"/>
     </path>
 
     <taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
@@ -1570,7 +1596,7 @@
     </path>
   </target>
 
-  <target name="cobertura-report" if="${test.cobertura}"
+  <target name="cobertura-report" if="${cobertura.enabled}"
           depends="test-bio,test-nio,test-apr"
           description="Creates report from gathered Cobertura results">
 
diff --git a/test/org/apache/catalina/startup/LoggingBaseTest.java b/test/org/apache/catalina/startup/LoggingBaseTest.java
index 833857b..2bd7f48 100644
--- a/test/org/apache/catalina/startup/LoggingBaseTest.java
+++ b/test/org/apache/catalina/startup/LoggingBaseTest.java
@@ -97,10 +97,13 @@ public abstract class LoggingBaseTest {
     @BeforeClass
     public static void setUpPerTestClass() throws Exception {
         // Create catalina.base directory
-        tempDir = new File(System.getProperty("tomcat.test.temp", "output/tmp"));
-        if (!tempDir.mkdirs() && !tempDir.isDirectory()) {
-            Assert.fail("Unable to create temporary directory for test");
+        File tempBase = new File(System.getProperty("tomcat.test.temp", "output/tmp"));
+        if (!tempBase.mkdirs() && !tempBase.isDirectory()) {
+            Assert.fail("Unable to create base temporary directory for tests");
         }
+        tempDir = File.createTempFile("test", null, tempBase);
+        Assert.assertTrue(tempDir.delete());
+        Assert.assertTrue(tempDir.mkdirs());
 
         System.setProperty("catalina.base", tempDir.getAbsolutePath());
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 094e0eb..e78b9e2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -86,6 +86,13 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="Other">
+    <changelog>
+      <add>
+        Enable the unit tests to execute in parallel. (markt)
+      </add>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 7.0.95 (violetagg)" rtext="not released">
   <subsection name="Catalina">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org