-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Spec: Add ability to randomize specs #8310
Conversation
@asterite Updated. |
Does it randomize things level per level? Or is it global? Given 2 describes A/B/C, with 3
With your PR, will it randomize like:
Or like:
? |
@bew I would expect randomization to happen inside individual |
Comparing with rspec, it has two different options:
I suppose it's fine to merge them into one since there don't seem to be any additional use cases. rspec's default seed value is in |
Per-level. This is particularly important for verbose output and before/after hooks, otherwise it would interleave improperly.
I find rspec's CLI confusing, and this seemed a lot simpler. I can change though if we all agree on a different CLI interface.
When I started this exercise I was pulling the values out of the Random::PCG32, which was a pair of UInt64s, and I converted those to a hex string for ease of use. But now, after @asterite's suggestion to generate a seed right in the Spec module, I can definitely do this, since I control the value. |
Updated with all suggestions. (EDIT: Also updated the OP with new screenshots) For the random seed range I chose |
5a3b832
to
9582e74
Compare
def self.order=(mode) | ||
seed = | ||
case mode | ||
when "default" |
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.
Hmm I don't like the strings being used here. At least it could be symbols. Or change it to seed=
, random_seed
.
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.
The methods in this DSL module are basically the implementation of the CLI, so I'd like to keep it as close to the CLI as possible. This includes incoming values as strings, and the method being named order=
to match the --order
CLI param.
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 have comments about a few minor details, but this is (almost) good to go!
@straight-shoota @RX14 I've rebased this and fixed the small comments, so this should be good to go. |
* Add support for randomized specs * Add support for running specs with a seeded random order * Move randomization to a helper method * Avoid using a regex, and allow the seed to be any number * Cleanup from PR comments
This PR adds the ability to run specs in a random order. To do so, just pass
--order random
tocrystal spec
. Randomized specs will output a seed which can be used if the tests need to be run in the same previous random order. To do so, just pass--order <seed-value>
.Default

With random

With seed

Note that this PR takes some of the test infrastructure stuff I built in #8242 in order to test the randomization.