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
Conversation
There is IT test: RunOrderIT Maybe assertions can be added to verify it. |
|
d15079a
to
0847b1d
Compare
@slawekjaranowski how do I get the PR template back? What's wrong with my IT test? |
you cen edit PR description and copy template from https://github.com/apache/maven-surefire/blob/master/.github/pull_request_template.md |
build approval ... we will see the result |
OutputValidator validator = executeWithRandomOrder( "junit4", seed ); | ||
validator.verifyTextInLog( "To reproduce ordering use flag" ); | ||
validator = executeWithRandomOrder( "junit4" ); | ||
validator.verifyTextInLog( "To reproduce ordering use flag" ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 );
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 );
.
There was a problem hiding this comment.
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?
surefire-its/src/test/java/org/apache/maven/surefire/its/RunOrderIT.java
Outdated
Show resolved
Hide resolved
setRunOrderRandomSeed( System.nanoTime() ); | ||
if ( getRunOrderRandomSeed() == null ) | ||
{ | ||
setRunOrderRandomSeed( System.nanoTime() ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
Show resolved
Hide resolved
this.random = new Random( runOrderRandomSeed == null ? System.nanoTime() : runOrderRandomSeed ); | ||
random = runOrderRandomSeed == null ? null : new Random( runOrderRandomSeed ); |
There was a problem hiding this comment.
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 );
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@Tibor17 any more remarks ... I'm going to merge it. |
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.