You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2016/11/30 22:22:33 UTC

[3/3] maven-surefire git commit: Merge branch 'master' of https://github.com/apache/maven-surefire into SUREFIRE-1295

Merge branch 'master' of https://github.com/apache/maven-surefire into SUREFIRE-1295

Conflicts:
	maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/648c9671
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/648c9671
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/648c9671

Branch: refs/heads/master
Commit: 648c967171bb94c262c15fc5393ba813c313cdfb
Parents: 9272881
Author: Tibor17 <ti...@lycos.com>
Authored: Wed Nov 30 23:13:07 2016 +0100
Committer: Tibor17 <ti...@lycos.com>
Committed: Wed Nov 30 23:13:07 2016 +0100

----------------------------------------------------------------------
 .../booterclient/output/ForkClient.java         |   4 +
 .../src/site/apt/examples/shutdown.apt.vm       |   8 +-
 maven-surefire-plugin/src/site/fml/faq.fml      |  10 ++
 ...urefire1295AttributeJvmCrashesToTestsIT.java | 117 +++++++++++++++++++
 .../test/resources/crash-during-test/pom.xml    |  65 +++++++++++
 .../java/junit44/environment/BasicTest.java     |  52 +++++++++
 .../java/junit44/environment/SomeOtherTest.java |  28 +++++
 7 files changed, 283 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
index 1472aa4..898a165 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
@@ -35,7 +35,11 @@ import java.io.StringReader;
 import java.nio.ByteBuffer;
 import java.util.NoSuchElementException;
 import java.util.Properties;
+import java.util.Queue;
+import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicLong;
 
 import static java.lang.Integer.decode;

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm b/maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm
index 7e943a5..9257c42 100644
--- a/maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/shutdown.apt.vm
@@ -85,4 +85,10 @@ Shutdown of Forked JVM
   amount of time and the whole plugin fails with the error message:
 
   <<<There was a timeout or other error in the fork>>>
-  
+
+
+* Crashed forked JVM caused listing the crashed test(s)
+
+  After the JVM exited abruptly, the console lists the message <<<Crashed tests:>>> if the entire
+  test-set has not been yet completed. This happens if a test exited, killed JVM or segmentation fault crashed JVM.
+

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/maven-surefire-plugin/src/site/fml/faq.fml
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/fml/faq.fml b/maven-surefire-plugin/src/site/fml/faq.fml
index 6be7913..de736dd 100644
--- a/maven-surefire-plugin/src/site/fml/faq.fml
+++ b/maven-surefire-plugin/src/site/fml/faq.fml
@@ -67,6 +67,16 @@ under the License.
         </p>
       </answer>
     </faq>
+    <faq id="crashed-forks">
+      <question>Crashed Surefire or Failsafe plugin must indicate crashed tests</question>
+      <answer>
+        <p>
+        After a forked JVM has crashed the console of forked JVM prints <em>Crashed tests:</em> and lists the last test
+        which has crashed. In the console log you can find the message
+        <em>The forked VM terminated without properly saying goodbye</em>.
+        </p>
+      </answer>
+    </faq>
     <faq id="GWT">
       <question>How can I run GWT tests?</question>
       <answer>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1295AttributeJvmCrashesToTestsIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1295AttributeJvmCrashesToTestsIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1295AttributeJvmCrashesToTestsIT.java
new file mode 100644
index 0000000..94532b9
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1295AttributeJvmCrashesToTestsIT.java
@@ -0,0 +1,117 @@
+package org.apache.maven.surefire.its.jiras;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.surefire.its.fixture.OutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Iterator;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeFalse;
+
+/**
+ * https://issues.apache.org/jira/browse/SUREFIRE-1295
+ * https://github.com/apache/maven-surefire/pull/136
+ *
+ * @author michaeltandy
+ * @since 2.19.2
+ */
+public class Surefire1295AttributeJvmCrashesToTestsIT
+        extends SurefireJUnit4IntegrationTestCase
+{
+    @Before
+    public void skipWindows()
+    {
+        assumeFalse( System.getProperty( "os.name" ).startsWith( "Windows" ) );
+    }
+
+    @Test
+    public void crashInFork() throws VerificationException
+    {
+        SurefireLauncher launcher = unpack( "crash-during-test" );
+
+        checkCrashTypes( launcher );
+    }
+
+    @Test
+    public void crashInSingleUseFork() throws VerificationException
+    {
+        SurefireLauncher launcher = unpack( "crash-during-test" )
+                                            .forkCount( 1 )
+                                            .reuseForks( false );
+
+        checkCrashTypes( launcher );
+    }
+
+    @Test
+    public void crashInReusableFork() throws VerificationException
+    {
+        SurefireLauncher launcher = unpack( "crash-during-test" )
+                                            .forkOncePerThread()
+                                            .threadCount( 1 );
+
+        checkCrashTypes( launcher );
+    }
+
+    private static void checkCrashTypes( SurefireLauncher launcher )
+            throws VerificationException
+    {
+        checkCrash( launcher.addGoal( "-DcrashType=exit" ) );
+        checkCrash( launcher.addGoal( "-DcrashType=abort" ) );
+        checkCrash( launcher.addGoal( "-DcrashType=segfault" ) );
+    }
+
+    private static void checkCrash( SurefireLauncher launcher ) throws VerificationException
+    {
+        OutputValidator validator = launcher.maven()
+                                            .withFailure()
+                                            .executeTest()
+                                            .verifyTextInLog( "The forked VM terminated without properly saying "
+                                                                      + "goodbye. VM crash or System.exit called?"
+                                            )
+                                            .verifyTextInLog( "Crashed tests:" );
+
+        for ( Iterator<String> it = validator.loadLogLines().iterator(); it.hasNext(); )
+        {
+            String line = it.next();
+            if ( line.contains( "Crashed tests:" ) )
+            {
+                line = it.next();
+                if ( it.hasNext() )
+                {
+                    assertThat( line ).contains( "junit44.environment.BasicTest" );
+                }
+                else
+                {
+                    fail( "Could not find any line after 'Crashed tests:'." );
+                }
+            }
+        }
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/surefire-integration-tests/src/test/resources/crash-during-test/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/crash-during-test/pom.xml b/surefire-integration-tests/src/test/resources/crash-during-test/pom.xml
new file mode 100644
index 0000000..38134bd
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/crash-during-test/pom.xml
@@ -0,0 +1,65 @@
+<?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">
+  <parent>
+    <groupId>org.apache.maven.surefire</groupId>
+    <artifactId>it-parent</artifactId>
+    <version>1.0</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>crash-during-test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Tests vm crash while a test is in progress</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.4</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>uk.me.mjt</groupId>
+      <artifactId>crashjvm</artifactId>
+      <version>1.0</version>
+      <scope>test</scope>
+      <type>jar</type>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+        <configuration>
+          <forkMode>once</forkMode>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/BasicTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/BasicTest.java b/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/BasicTest.java
new file mode 100644
index 0000000..57d57bb
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/BasicTest.java
@@ -0,0 +1,52 @@
+package junit44.environment;
+
+/*
+ * 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.
+ */
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import uk.me.mjt.CrashJvm;
+
+public class BasicTest
+{
+    @Test
+    public void testCrashJvm()
+    {
+        assertTrue(CrashJvm.loadedOk());
+        
+        String crashType = System.getProperty("crashType");
+        assertNotNull(crashType);
+        if ( crashType.equals( "exit" ) )
+        {
+            CrashJvm.exit();
+        }
+        else if ( crashType.equals( "abort" ) )
+        {
+            CrashJvm.abort();
+        }
+        else if (crashType.equals( "segfault" ))
+        {
+            CrashJvm.segfault();
+        }
+        else
+        {
+            fail("Don't recognise crashType " + crashType);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/648c9671/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/SomeOtherTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/SomeOtherTest.java b/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/SomeOtherTest.java
new file mode 100644
index 0000000..e10f6aa
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/crash-during-test/src/test/java/junit44/environment/SomeOtherTest.java
@@ -0,0 +1,28 @@
+
+package junit44.environment;
+
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+public class SomeOtherTest {
+    @Test
+    public void nonCrashingTest() {}
+}