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 2022/02/03 05:31:00 UTC

[maven-surefire] branch InterruptedIOException updated (5b8e23b -> 16b11a2)

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

tibordigana pushed a change to branch InterruptedIOException
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git.


 discard 5b8e23b  [SUREFIRE-1998] Interrupted PPID Checker should have the same meaning as stopped PPID Checker
 discard a2e6fe4  interrupted PpidChecker = error, more logs
     new f04e33b  [SUREFIRE-1998] Interrupted PPID Checker should have the same meaning as stopped PPID Checker
     new 16b11a2  [SUREFIRE-1999] PPID checker should redirect the error stream of the checker command to a dump file

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5b8e23b)
            \
             N -- N -- N   refs/heads/InterruptedIOException (16b11a2)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:

[maven-surefire] 02/02: [SUREFIRE-1999] PPID checker should redirect the error stream of the checker command to a dump file

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch InterruptedIOException
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 16b11a2c17d3b40605cfbe7b4f985300008d7560
Author: Tibor Digaňa <ti...@apache.org>
AuthorDate: Thu Feb 3 06:20:07 2022 +0100

    [SUREFIRE-1999] PPID checker should redirect the error stream of the checker command to a dump file
---
 .../apache/maven/surefire/booter/PpidChecker.java  | 27 ++++++++++-
 .../maven/surefire/booter/PpidCheckerTest.java     | 56 ++++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
index a5287c7..3eb703d 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
@@ -25,6 +25,7 @@ import javax.annotation.Nonnull;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.Charset;
+import java.nio.file.Path;
 import java.text.SimpleDateFormat;
 import java.util.Queue;
 import java.util.Scanner;
@@ -36,6 +37,9 @@ import java.util.regex.Pattern;
 import static java.lang.Integer.parseInt;
 import static java.lang.Long.parseLong;
 import static java.lang.String.join;
+import static java.nio.file.Files.createTempFile;
+import static java.nio.file.Files.delete;
+import static java.nio.file.Files.readAllBytes;
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.MINUTES;
@@ -394,14 +398,16 @@ final class PpidChecker
         ProcessInfo execute( String... command )
         {
             ProcessBuilder processBuilder = new ProcessBuilder( command );
-            processBuilder.redirectErrorStream( true );
             Process process = null;
             ProcessInfo processInfo = INVALID_PROCESS_INFO;
             StringBuilder out = new StringBuilder( 64 );
             out.append( join( " ", command ) )
                 .append( NL );
+            Path stdErr = null;
             try
             {
+                stdErr = createTempFile( "surefire", null );
+                processBuilder.redirectError( stdErr.toFile() );
                 if ( IS_OS_HP_UX ) // force to run shell commands in UNIX Standard mode on HP-UX
                 {
                     processBuilder.environment().put( "UNIX95", "1" );
@@ -447,11 +453,28 @@ final class PpidChecker
                 if ( process != null )
                 {
                     destroyableCommands.remove( process );
-                    process.destroy();
                     closeQuietly( process.getInputStream() );
                     closeQuietly( process.getErrorStream() );
                     closeQuietly( process.getOutputStream() );
                 }
+
+                if ( stdErr != null )
+                {
+                    try
+                    {
+                        String error = new String( readAllBytes( stdErr ) ).trim();
+                        if ( !error.isEmpty() )
+                        {
+                            DumpErrorSingleton.getSingleton()
+                                .dumpText( error );
+                        }
+                        delete( stdErr );
+                    }
+                    catch ( IOException e )
+                    {
+                        // cannot do anything about it, the dump file writes would fail as well
+                    }
+                }
             }
         }
     }
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
index 5f7a744..d9431e1 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.booter;
  * under the License.
  */
 
+import org.apache.maven.surefire.api.booter.DumpErrorSingleton;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -27,7 +28,9 @@ import java.io.File;
 import java.lang.management.ManagementFactory;
 import java.util.regex.Matcher;
 
+import static java.nio.file.Files.readAllBytes;
 import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.maven.surefire.shared.io.FileUtils.getTempDirectory;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_UNIX;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
 import static org.apache.maven.surefire.booter.ProcessInfo.unixProcessInfo;
@@ -150,6 +153,59 @@ public class PpidCheckerTest
     }
 
     @Test
+    public void shouldBeStoppedCheckerWithError() throws Exception
+    {
+        String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+        DumpErrorSingleton.getSingleton().init( getTempDirectory(), "dump" );
+
+        PpidChecker checker = new PpidChecker( expectedPid );
+        checker.stop();
+
+        ProcessInfo processInfo = IS_OS_UNIX ? checker.unix() : checker.windows();
+        assertThat( processInfo.isError() ).isTrue();
+
+        File dump = DumpErrorSingleton.getSingleton().dumpText( null );
+        dump.deleteOnExit();
+
+        String error = new String( readAllBytes( dump.toPath() ) );
+
+        assertThat( error )
+            .contains( "<<exit>> <<0>>" )
+            .contains( "<<stopped>> <<true>>" );
+    }
+
+    @Test
+    public void shouldBeEmptyDump() throws Exception
+    {
+        String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
+        DumpErrorSingleton.getSingleton().init( getTempDirectory(), "dump" );
+
+        PpidChecker checker = new PpidChecker( expectedPid );
+        Thread.currentThread().interrupt();
+
+        ProcessInfo processInfo = IS_OS_UNIX ? checker.unix() : checker.windows();
+        assertThat( processInfo.isError() ).isTrue();
+
+        // a hack to obtain the file
+        File dump = DumpErrorSingleton.getSingleton().dumpText( null );
+
+        dump.deleteOnExit();
+
+        String error = new String( readAllBytes( dump.toPath() ) ).trim();
+
+        String[] lines = error.split( "\r\n|\r|\n" );
+
+        assertThat( lines.length )
+            .isEqualTo( 2 );
+
+        assertThat( lines[0] )
+            .startsWith( "# Created at " );
+
+        assertThat( lines[1] )
+            .isEqualTo( "null" );
+    }
+
+    @Test
     public void shouldNotFindSuchPID()
     {
         PpidChecker checker = new PpidChecker( "1000000" );

[maven-surefire] 01/02: [SUREFIRE-1998] Interrupted PPID Checker should have the same meaning as stopped PPID Checker

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch InterruptedIOException
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit f04e33bc3e7ee156241d02a50b9a33906d5afcbd
Author: Tibor Digaňa <ti...@apache.org>
AuthorDate: Tue Feb 1 15:01:03 2022 +0100

    [SUREFIRE-1998] Interrupted PPID Checker should have the same meaning as stopped PPID Checker
---
 .../java/org/apache/maven/surefire/booter/PpidChecker.java  | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
index ff5d77c..a5287c7 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
@@ -35,6 +35,7 @@ import java.util.regex.Pattern;
 
 import static java.lang.Integer.parseInt;
 import static java.lang.Long.parseLong;
+import static java.lang.String.join;
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.MINUTES;
@@ -397,6 +398,8 @@ final class PpidChecker
             Process process = null;
             ProcessInfo processInfo = INVALID_PROCESS_INFO;
             StringBuilder out = new StringBuilder( 64 );
+            out.append( join( " ", command ) )
+                .append( NL );
             try
             {
                 if ( IS_OS_HP_UX ) // force to run shell commands in UNIX Standard mode on HP-UX
@@ -414,13 +417,17 @@ final class PpidChecker
                 }
                 checkValid( scanner );
                 int exitCode = process.waitFor();
-                if ( exitCode != 0 || isStopped() )
+                boolean isError = Thread.interrupted() || isStopped();
+                if ( exitCode != 0 || isError )
                 {
-                    out.append( "<<exit>> <<" ).append( exitCode ).append( ">>" ).append( NL );
+                    out.append( "<<exit>> <<" ).append( exitCode ).append( ">>" )
+                        .append( NL )
+                        .append( "<<stopped>> <<" ).append( isStopped() ).append( ">>" );
                     DumpErrorSingleton.getSingleton()
                             .dumpText( out.toString() );
                 }
-                return isStopped() ? ERR_PROCESS_INFO : exitCode == 0 ? processInfo : INVALID_PROCESS_INFO;
+
+                return isError ? ERR_PROCESS_INFO : ( exitCode == 0 ? processInfo : INVALID_PROCESS_INFO );
             }
             catch ( Exception e )
             {