maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r598096 - in /maven/surefire/trunk: maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/ surefire-booter/src/main/java/org/apache/maven/surefire/booter/ surefire-integration-tests/src/test/java/org/apache/maven/surefire/its...
Date Mon, 26 Nov 2007 00:20:47 GMT
Author: dfabulich
Date: Sun Nov 25 16:20:46 2007
New Revision: 598096

URL: http://svn.apache.org/viewvc?rev=598096&view=rev
Log:
[SUREFIRE-320] Time out and kill forked test process

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TimeoutForkedTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/   (with
props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/BasicTest.java
Modified:
    maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Modified: maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=598096&r1=598095&r2=598096&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Sun Nov 25 16:20:46 2007
@@ -303,6 +303,14 @@
     private String debugForkedProcess;
     
     /**
+     * Kill the forked test process after a certain number of seconds.  If set to 0,
+     * wait forever for the process, never timing out.
+     * 
+     * @parameter expression="${surefire.timeout}"
+     */
+    private int forkedProcessTimeoutInSeconds;
+    
+    /**
      * Additional environments to set on the command line.
      * 
      * @parameter
@@ -834,6 +842,8 @@
         }
         
         surefireBooter.setFailIfNoTests( failIfNoTests );
+        
+        surefireBooter.setForkedProcessTimeoutInSeconds( forkedProcessTimeoutInSeconds );
 
         surefireBooter.setRedirectTestOutputToFile( redirectTestOutputToFile );
 

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=598096&r1=598095&r2=598096&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Sun Nov 25 16:20:46 2007
@@ -80,6 +80,8 @@
     private List testSuites = new ArrayList();
     
     private boolean failIfNoTests = false;
+    
+    private int forkedProcessTimeoutInSeconds = 0;
 
     private boolean redirectTestOutputToFile = false;
 
@@ -654,7 +656,7 @@
 
         try
         {
-            returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
+            returnCode = CommandLineUtils.executeCommandLine( cli, out, err, forkedProcessTimeoutInSeconds
);
         }
         catch ( CommandLineException e )
         {
@@ -1020,5 +1022,10 @@
     public void setEnableAssertions( boolean enableAssertions )
     {
         this.enableAssertions = enableAssertions;
+    }
+    
+    public void setForkedProcessTimeoutInSeconds( int forkedProcessTimeoutInSeconds )
+    {
+        this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds;
     }
 }

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TimeoutForkedTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TimeoutForkedTest.java?rev=598096&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TimeoutForkedTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TimeoutForkedTest.java
Sun Nov 25 16:20:46 2007
@@ -0,0 +1,36 @@
+package org.apache.maven.surefire.its;
+
+import java.io.File;
+
+import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test 
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class TimeoutForkedTest
+    extends AbstractMavenIntegrationTestCase
+{
+    public void testTimeoutForked ()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/timeout-forked"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.executeGoal( "test" );
+        verifier.resetStreams();
+        try {
+            verifier.verifyErrorFreeLog();
+            fail( "Build didn't fail, but it should have" );
+        } catch (VerificationException e) 
+        {
+            // as expected
+        }
+        
+    }
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Nov 25 16:20:46 2007
@@ -0,0 +1,5 @@
+.classpath
+.project
+target
+.settings
+log.txt

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/pom.xml?rev=598096&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/pom.xml
Sun Nov 25 16:20:46 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>timeout-forked</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Timeout forked process</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkedProcessTimeoutInSeconds>3</forkedProcessTimeoutInSeconds>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/BasicTest.java?rev=598096&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/BasicTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/timeout-forked/src/test/java/timeoutForked/BasicTest.java
Sun Nov 25 16:20:46 2007
@@ -0,0 +1,17 @@
+package timeoutForked;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BasicTest
+    extends TestCase
+{
+
+    public void testSleep() throws Exception
+    {
+        Thread.sleep(10000);
+    }
+
+}



Mime
View raw message