Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-2055] Always show random seed #505

Merged
merged 2 commits into from May 4, 2022

Conversation

delanym
Copy link
Contributor

@delanym delanym commented Apr 3, 2022

Always show the random seed when using the random runOrder. This is so tests that fail because of their runOrder can be replayed without necessarily knowing the build command.

@slawekjaranowski
Copy link
Member

There is IT test: RunOrderIT

Maybe assertions can be added to verify it.

@slawekjaranowski
Copy link
Member

@delanym

  • please check build result
  • PR template contains important things - should be preserved

@delanym delanym force-pushed the SUREFIRE-2055 branch 2 times, most recently from d15079a to 0847b1d Compare April 5, 2022 21:35
@delanym
Copy link
Contributor Author

delanym commented Apr 5, 2022

@slawekjaranowski how do I get the PR template back? What's wrong with my IT test?

@slawekjaranowski
Copy link
Member

you cen edit PR description and copy template from https://github.com/apache/maven-surefire/blob/master/.github/pull_request_template.md

@slawekjaranowski
Copy link
Member

build approval ... we will see the result

Comment on lines 105 to 112
OutputValidator validator = executeWithRandomOrder( "junit4", seed );
validator.verifyTextInLog( "To reproduce ordering use flag" );
validator = executeWithRandomOrder( "junit4" );
validator.verifyTextInLog( "To reproduce ordering use flag" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider to split into two test, eg:

  • testRandomJUnit4PrintSeedWithGivenSeed
  • testRandomJUnit4PrintSeedWithNoGivenSeed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @delanym . Nice to meet you after the release Vote!
I know that it is a matter of taste but these names of classes and methods determine the length of folders on the file system in our CI. Using WithSeed and WithoutSeed is shorter.
Now, I have realized that @delanym is using two executions which might be utilized in some way.
@delanym what wat your point? You wanted to compare the XML reports and the order of tests? Something else? If you want to make sure that the seed is set, such situation can be verified with the old IT where a debug message can be printed in the logs and the IT can check that the message was printed with seed != NULL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that new tests verify if expected message is printed in standard info level nevermind if seed is given or not.
Message should be printed always for random orders.

ok, name of test method can be shorter 😄 , but in this case is only 40 chars it is acceptable

Copy link
Contributor

@Tibor17 Tibor17 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delanym
We are doing these things twice. The seed is set to System.nanoTime() if it was NULL, see DefaultRunOrderCalculator.
This means that the only work here should be different, we should change the condition in the IF statement but nothing more. WDYT? Pls comment on this!

        Long runOrderRandomSeed = runOrderParameters.getRunOrderRandomSeed();
        if ( runOrderRandomSeed == null )
        {
            runOrderRandomSeed = System.nanoTime();
            runOrderParameters.setRunOrderRandomSeed( runOrderRandomSeed );
        }
        this.random = new Random( runOrderRandomSeed );

Copy link
Contributor

@Tibor17 Tibor17 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski Do you remember all the years we solved together with Robert and Infra team because the Windows paths were limited on the file system? They are still limitted however the limit is longer but it still exists! Also the infra team prolonged the limit of CMD line in bash but it still exists.

Copy link
Contributor

@Tibor17 Tibor17 Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delanym I made RunOrderParameters immutable because the contributor did not implement it right and the setter was not necessary. Pls rebase your branch on origin/master. You should exclude the fallback value System.nanoTime() in the DefaultRunOrderCalculator constructor and use it only in MOJO. It does not make sense to do one thing twice with the seed.
Finally this.random = new Random( runOrderRandomSeed == null ? System.nanoTime() : runOrderRandomSeed ); would become random = runOrderRandomSeed == null ? null : new Random( runOrderRandomSeed );.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have I done that right?

setRunOrderRandomSeed( System.nanoTime() );
if ( getRunOrderRandomSeed() == null )
{
setRunOrderRandomSeed( System.nanoTime() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would expect some warning that the seed is missing.
If random, then yes, we should use random and prevent from any cohesion between the neighbouring runs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see the implementation, because the impl has much better opportunities to use real random number if this parameter is NULL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runOrderRandomSeed is never NULLm if is not provided it will be set to nanoTime.

Currently is printed only when is not given in configuration, change introduce to print always - also if is given by configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slawekjaranowski runOrder can be other than random and so DefaultRunOrderCalculator may obtain null seed.
@delanym see my comment #505 (comment)

this.random = new Random( runOrderRandomSeed == null ? System.nanoTime() : runOrderRandomSeed );
random = runOrderRandomSeed == null ? null : new Random( runOrderRandomSeed );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change in this way ...?
When rundom will be null we will have NPE from Collections.shuffle( testClasses, random );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO here runOrderParameters.getRunOrderRandomSeed(); never be null

Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@slawekjaranowski
Copy link
Member

@Tibor17 any more remarks ... I'm going to merge it.

@slawekjaranowski slawekjaranowski merged commit a4cdc02 into apache:master May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants