Skip to content

Commit

Permalink
[SUREFIRE-2055] Always show random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
delanym committed Apr 9, 2022
1 parent 157d2d9 commit 1e9db1f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Expand Up @@ -3114,9 +3114,12 @@ protected void warnIfIllegalFailOnFlakeCount() throws MojoFailureException

private void printDefaultSeedIfNecessary()
{
if ( getRunOrderRandomSeed() == null && getRunOrder().equals( RunOrder.RANDOM.name() ) )
if ( getRunOrder().equals( RunOrder.RANDOM.name() ) )
{
setRunOrderRandomSeed( System.nanoTime() );
if ( getRunOrderRandomSeed() == null )
{
setRunOrderRandomSeed( System.nanoTime() );
}
getConsoleLogger().info(
"Tests will run in random order. To reproduce ordering use flag -D"
+ getPluginName() + ".runOrder.random.seed=" + getRunOrderRandomSeed() );
Expand Down
Expand Up @@ -55,7 +55,7 @@ public DefaultRunOrderCalculator( RunOrderParameters runOrderParameters, int thr
this.runOrder = runOrderParameters.getRunOrder();
this.sortOrder = this.runOrder.length > 0 ? getSortOrderComparator( this.runOrder[0] ) : null;
Long runOrderRandomSeed = runOrderParameters.getRunOrderRandomSeed();
this.random = new Random( runOrderRandomSeed == null ? System.nanoTime() : runOrderRandomSeed );
random = runOrderRandomSeed == null ? null : new Random( runOrderRandomSeed );
}

@Override
Expand Down
Expand Up @@ -97,7 +97,21 @@ public void testRandomJUnit4SameSeed()
}
}
}


@Test
public void testRandomJUnit4PrintSeedWithGivenSeed()
{
OutputValidator validator = executeWithRandomOrder( "junit4", 0L );
validator.verifyTextInLog( "To reproduce ordering use flag" );
}

@Test
public void testRandomJUnit4PrintSeedWithNoGivenSeed()
{
OutputValidator validator = executeWithRandomOrder( "junit4" );
validator.verifyTextInLog( "To reproduce ordering use flag" );
}

@Test
public void testReverseAlphabeticalJUnit4()
throws Exception
Expand Down Expand Up @@ -187,6 +201,16 @@ private OutputValidator executeWithRunOrder( String runOrder, String profile )
.verifyErrorFree( 3 );
}

private OutputValidator executeWithRandomOrder( String profile )
{
return unpack()
.activateProfile( profile )
.forkMode( getForkMode() )
.runOrder( "random" )
.executeTest()
.verifyErrorFree( 3 );
}

private OutputValidator executeWithRandomOrder( String profile, long seed )
{
return unpack()
Expand Down

0 comments on commit 1e9db1f

Please sign in to comment.