Skip to content

Commit

Permalink
[SUREFIRE-1935] start a new LauncherSession for every failure rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
papegaaij committed Dec 21, 2021
1 parent d04d210 commit f4beedc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
Expand Up @@ -111,17 +111,7 @@ public Iterable<Class<?>> getSuites()
}
finally
{
if ( launcher instanceof AutoCloseable )
{
try
{
( (AutoCloseable) launcher ).close();
}
catch ( Exception e )
{
throw new SurefireReflectionException( e );
}
}
closeLauncher();
}
}

Expand Down Expand Up @@ -156,17 +146,6 @@ else if ( forkTestSet == null )
finally
{
runResult = reporterFactory.close();
if ( launcher instanceof AutoCloseable )
{
try
{
( (AutoCloseable) launcher ).close();
}
catch ( Exception e )
{
throw new SurefireReflectionException( e );
}
}
}
return runResult;
}
Expand All @@ -182,22 +161,37 @@ private TestsToRun scanClasspath()
private void invokeAllTests( TestsToRun testsToRun, RunListener runListener )
{
RunListenerAdapter adapter = new RunListenerAdapter( runListener );
execute( testsToRun, adapter );
try
{
execute( testsToRun, adapter );
}
finally
{
closeLauncher();
}
// Rerun failing tests if requested
int count = parameters.getTestRequest().getRerunFailingTestsCount();
if ( count > 0 && adapter.hasFailingTests() )
{
for ( int i = 0; i < count; i++ )
{
// Replace the "discoveryRequest" so that it only specifies the failing tests
LauncherDiscoveryRequest discoveryRequest = buildLauncherDiscoveryRequestForRerunFailures( adapter );
// Reset adapter's recorded failures and invoke the failed tests again
adapter.reset();
launcher.execute( discoveryRequest, adapter );
// If no tests fail in the rerun, we're done
if ( !adapter.hasFailingTests() )
try
{
// Replace the "discoveryRequest" so that it only specifies the failing tests
LauncherDiscoveryRequest discoveryRequest =
buildLauncherDiscoveryRequestForRerunFailures( adapter );
// Reset adapter's recorded failures and invoke the failed tests again
adapter.reset();
launcher.execute( discoveryRequest, adapter );
// If no tests fail in the rerun, we're done
if ( !adapter.hasFailingTests() )
{
break;
}
}
finally
{
break;
closeLauncher();
}
}
}
Expand Down Expand Up @@ -231,6 +225,21 @@ private void execute( TestsToRun testsToRun, RunListenerAdapter adapter )
} );
}
}

private void closeLauncher()
{
if ( launcher instanceof AutoCloseable )
{
try
{
( (AutoCloseable) launcher ).close();
}
catch ( Exception e )
{
throw new SurefireReflectionException( e );
}
}
}

private LauncherDiscoveryRequest buildLauncherDiscoveryRequestForRerunFailures( RunListenerAdapter adapter )
{
Expand Down
Expand Up @@ -79,6 +79,8 @@ public void close() throws Exception
if ( launcherSession != null )
{
launcherSession.close();
launcherSession = null;
}
launcher = null;
}
}

0 comments on commit f4beedc

Please sign in to comment.