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 2019/11/12 13:13:23 UTC
[maven-surefire] branch SUREFIRE-1631 updated: build fix
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch SUREFIRE-1631
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/SUREFIRE-1631 by this push:
new 96376d4 build fix
96376d4 is described below
commit 96376d45ae5888c424200a21e8d6a252d81532bd
Author: tibordigana <ti...@apache.org>
AuthorDate: Tue Nov 12 14:13:13 2019 +0100
build fix
---
.../apache/maven/surefire/booter/PpidChecker.java | 32 ++++++++++------------
.../maven/surefire/booter/PpidCheckerTest.java | 17 ++++++++++++
2 files changed, 32 insertions(+), 17 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 5bcb7a3..d091ca6 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
@@ -56,7 +56,7 @@ import static org.apache.maven.surefire.util.internal.StringUtils.NL;
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.20.1
*/
-final class PpidChecker
+class PpidChecker
{
private static final int MINUTES_TO_MILLIS = 60 * 1000;
// 25 chars https://superuser.com/questions/937380/get-creation-time-of-file-in-milliseconds/937401#937401
@@ -128,14 +128,7 @@ final class PpidChecker
boolean isAlive = !parentProcessInfo.isInvalid()
&& ( previousInfo == null || parentProcessInfo.isTimeEqualTo( previousInfo ) );
- if ( !isFirstCheckFailed )
- {
- isFirstCheckFailed = previousInfo == null && !isAlive;
- if ( isFirstCheckFailed )
- {
- throw new IllegalStateException( "irrelevant to call isProcessAlive(), first check failed" );
- }
- }
+ fireOnFirstCommandFailure( previousInfo, isAlive );
return isAlive;
}
@@ -148,14 +141,7 @@ final class PpidChecker
boolean isAlive = !parentProcessInfo.isInvalid()
&& ( previousInfo == null || !parentProcessInfo.isTimeBefore( previousInfo ) );
- if ( !isFirstCheckFailed )
- {
- isFirstCheckFailed = previousInfo == null && !isAlive;
- if ( isFirstCheckFailed )
- {
- throw new IllegalStateException( "irrelevant to call isProcessAlive(), first check failed" );
- }
- }
+ fireOnFirstCommandFailure( previousInfo, isAlive );
return isAlive;
}
@@ -163,6 +149,18 @@ final class PpidChecker
throw new IllegalStateException( "unknown platform or you did not call canUse() before isProcessAlive()" );
}
+ private void fireOnFirstCommandFailure( ProcessInfo previousInfo, boolean isAlive )
+ {
+ if ( !isFirstCheckFailed )
+ {
+ isFirstCheckFailed = previousInfo == null && !isAlive;
+ if ( isFirstCheckFailed )
+ {
+ throw new IllegalStateException( "irrelevant to call isProcessAlive(), first check failed" );
+ }
+ }
+ }
+
private void checkProcessInfo()
{
if ( isStopped() )
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 915f2bc..52317e3 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
@@ -171,6 +171,8 @@ public class PpidCheckerTest
{
PpidChecker checker = new PpidChecker( "1000000" );
+ setInternalState( checker, "parentProcessInfo", ProcessInfo.unixProcessInfo( "", 0L ) );
+
assertThat( checker.canUse() )
.isTrue();
@@ -179,6 +181,21 @@ public class PpidCheckerTest
}
@Test
+ public void shouldFailFirstCheck()
+ {
+ PpidChecker checker = new PpidChecker( "1000000" );
+
+ assertThat( checker.canUse() )
+ .isTrue();
+
+ exceptions.expect( IllegalStateException.class );
+ exceptions.expectMessage( "irrelevant to call isProcessAlive(), first check failed" );
+
+ checker.isProcessAlive();
+
+ }
+
+ @Test
public void shouldParseEtime()
{
Matcher m = PpidChecker.UNIX_CMD_OUT_PATTERN.matcher( "38 1234567890" );