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

Report accurate ScalaCheck seed on failing test #195

Merged
merged 4 commits into from
Sep 9, 2020

Conversation

nevillelyh
Copy link
Contributor

@nevillelyh nevillelyh commented Sep 8, 2020

Failing seed reporting seems to be incorrect when scalaCheckInitialSeed is not overridden. In that case def seed would use def scalaCheckInitialSeed: String = Seed.random().toBase64 and be different every time. Hence the 2 seeds seen here are actually not the ones causing test failure.

https://travis-ci.org/github/spotify/magnolify/jobs/708925430#L369

Failing seed: z9omj4mAsT7BcJQoh95CcofqurdkO_jIAGEWFPx7xZA=
You can reproduce this failure by adding the following override to your suite:
  override val scalaCheckInitialSeed = "5E72c0hWZ5ioOvDIj2udNT9KuVs1mGz8EBcV-3zyKgH="

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! LGTM 👍

Any thoughts @gabro ?

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @nevillelyh for tracking this down and fixing it!

@nevillelyh
Copy link
Contributor Author

Not sure how to test though, probably need some variation of FrameworkTest, extract the seed from error message & verify.

@nevillelyh
Copy link
Contributor Author

Actually DO NOT MERGE. Let me verify if this actually works as expected first.

@olafurpg
Copy link
Member

olafurpg commented Sep 8, 2020

I am happy to merge without a test case (although it would be nice to have a test 😄 )

@nevillelyh
Copy link
Contributor Author

Think this actually broke another case. It's hard to verify since the test is non-deterministic 😭. At least let me verify some basic scenarios.

Copy link
Contributor Author

@nevillelyh nevillelyh left a comment

Choose a reason for hiding this comment

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

Added some comments. Seems to work now at least as far as my understanding of ScalaCheck & requirement goes.

scalaCheckTestParameters.initialSeed.getOrElse(
Seed.fromBase64(scalaCheckInitialSeed).get
)
val initialSeed = makeSeed()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be the actual "initial seed", one that's used to generate seeds for all test runs (default 100) of the same property.

val result = check(
scalaCheckTestParameters,
Prop(genParams => prop(genParams.withInitialSeed(seed)))
Prop { genParams =>
val r = prop(genParams.withInitialSeed(seed))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A single test run here. And advance seed to the next.

)
def renderResult(r: Result): String = {
val resultMessage = Pretty.pretty(r, scalaCheckPrettyParameters)
if (r.passed) {
resultMessage
} else {
val seedMessage = s"""|Failing seed: ${seed.toBase64}
val seedMessage = s"""|Failing seed: ${initialSeed.toBase64}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a test failed, say 67th out of 100, we still report the 1st seed in case the test is not pure.

final class ScalaCheckInitialSeedSuite extends ScalaCheckSuite {

// initial seed should be used for the first out of 100 `minSuccessfulTests` only
override val scalaCheckInitialSeed = "9SohH7wEYXCdXK4b9yM2d6TKIN2jBFcBs4QBta-2yTD="
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test checks that when initial seed is overridden, we still generate different input per test run instead of reusing the same.

@olafurpg olafurpg changed the title fix failing seed reporting Report accurate ScalaCheck seed on failing test Sep 9, 2020
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

@nevillelyh Thank you for double checking! A few minor comments, otherwise this looks ready to go

@@ -15,6 +15,26 @@ final class ScalaCheckSeedSuite extends ScalaCheckSuite {
}
}

test("generated int are not all the same") {
println(ints)
Copy link
Member

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}
}

final class ScalaCheckInitialSeedSuite extends ScalaCheckSuite {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to a separate file? I normally try to organize one test suite per file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I'll let @gabro do the merge

Copy link
Member

@gabro gabro left a comment

Choose a reason for hiding this comment

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

Thanks again!

@gabro gabro merged commit 0c4ff57 into scalameta:master Sep 9, 2020
@nevillelyh nevillelyh deleted the neville/seed branch September 9, 2020 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants