Skip to content

Commit

Permalink
[SUREFIRE-2023] The integration test Surefire946KillMainProcessInReus…
Browse files Browse the repository at this point in the history
…ableForkIT hanged and timed out because SIGTERM happened before the first test has started. The plugin should be able to terminate itself whenever after SIGTERM.
  • Loading branch information
Tibor17 committed Feb 23, 2022
1 parent e916128 commit d19f79f
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
import static org.apache.maven.surefire.shared.utils.StringUtils.isNotBlank;
import static org.apache.maven.surefire.shared.utils.StringUtils.isNotEmpty;
import static org.apache.maven.surefire.shared.utils.StringUtils.split;
import static org.apache.maven.surefire.shared.utils.cli.ShutdownHookUtils.addShutDownHook;
import static org.apache.maven.surefire.shared.utils.cli.ShutdownHookUtils.removeShutdownHook;

/**
* Abstract base class for running tests using Surefire.
Expand Down Expand Up @@ -922,29 +924,39 @@ public void execute()
// Stuff that should have been final
setupStuff();
Platform platform = PLATFORM.withJdkExecAttributesForTests( getEffectiveJvm() );

if ( verifyParameters() && !hasExecutedBefore() )
Thread shutdownThread = new Thread( platform::setShutdownState );
addShutDownHook( shutdownThread );
try
{
DefaultScanResult scan = scanForTestClasses();
if ( !hasSuiteXmlFiles() && scan.isEmpty() )
if ( verifyParameters() && !hasExecutedBefore() )
{
switch ( getEffectiveFailIfNoTests() )
DefaultScanResult scan = scanForTestClasses();
if ( !hasSuiteXmlFiles() && scan.isEmpty() )
{
case COULD_NOT_RUN_DEFAULT_TESTS:
throw new MojoFailureException(
"No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
case COULD_NOT_RUN_SPECIFIED_TESTS:
throw new MojoFailureException( "No tests matching pattern \""
+ getSpecificTests().toString()
+ "\" were executed! (Set "
+ "-D" + getPluginName() + ".failIfNoSpecifiedTests=false to ignore this error.)" );
default:
handleSummary( noTestsRun(), null );
return;
switch ( getEffectiveFailIfNoTests() )
{
case COULD_NOT_RUN_DEFAULT_TESTS:
throw new MojoFailureException(
"No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
case COULD_NOT_RUN_SPECIFIED_TESTS:
throw new MojoFailureException( "No tests matching pattern \""
+ getSpecificTests().toString()
+ "\" were executed! (Set "
+ "-D" + getPluginName()
+ ".failIfNoSpecifiedTests=false to ignore this error.)" );
default:
handleSummary( noTestsRun(), null );
return;
}
}
logReportsDirectory();
executeAfterPreconditionsChecked( scan, platform );
}
logReportsDirectory();
executeAfterPreconditionsChecked( scan, platform );
}
finally
{
platform.clearShutdownState();
removeShutdownHook( shutdownThread );
}
}

Expand Down Expand Up @@ -2446,7 +2458,7 @@ private InPluginVMSurefireStarter createInprocessStarter( @Nonnull ProviderInfo
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration( configChecksum, false );
ProviderConfiguration providerConfiguration = createProviderConfiguration( runOrderParameters );
return new InPluginVMSurefireStarter( startupConfiguration, providerConfiguration, startupReportConfiguration,
getConsoleLogger() );
getConsoleLogger(), platform );
}

// todo this is in separate method and can be better tested than whole method createForkConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import org.apache.maven.plugin.surefire.booterclient.Platform;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.ProviderConfiguration;
Expand Down Expand Up @@ -52,16 +53,18 @@ public class InPluginVMSurefireStarter
private final StartupReportConfiguration startupReportConfig;
private final ProviderConfiguration providerConfig;
private final ConsoleLogger consoleLogger;
private final Platform platform;

public InPluginVMSurefireStarter( @Nonnull StartupConfiguration startupConfig,
@Nonnull ProviderConfiguration providerConfig,
@Nonnull StartupReportConfiguration startupReportConfig,
@Nonnull ConsoleLogger consoleLogger )
@Nonnull ConsoleLogger consoleLogger, @Nonnull Platform platform )
{
this.startupConfig = startupConfig;
this.startupReportConfig = startupReportConfig;
this.providerConfig = providerConfig;
this.consoleLogger = consoleLogger;
this.platform = platform;
}

public RunResult runSuitesInProcess( @Nonnull DefaultScanResult scanResult )
Expand All @@ -84,7 +87,9 @@ public RunResult runSuitesInProcess( @Nonnull DefaultScanResult scanResult )

try
{
return invokeProvider( null, testClassLoader, factory, providerConfig, false, startupConfig, true );
return platform.isShutdown()
? new RunResult( 0, 0, 0, 0 )
: invokeProvider( null, testClassLoader, factory, providerConfig, false, startupConfig, true );
}
catch ( InvocationTargetException e )
{
Expand Down

0 comments on commit d19f79f

Please sign in to comment.