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

Make random order stable and platform-independent #974

Merged
merged 2 commits into from
May 15, 2016

Conversation

threedaymonk
Copy link
Contributor

@threedaymonk threedaymonk commented Apr 26, 2016

This makes two important changes to random ordering.

  1. Using the --order=random option with a particular seed will now produce the same order on every Ruby interpreter.
  2. The order is stable, so that if step A runs before step B with a given seed, it will still do so for that seed and suite even if intervening steps are skipped.

Previously, the random seed would produce consistent results on a given interpreter, but this could not always be reproduced on another version of Ruby. This occurred because Array#shuffle is implemented differently in different interpreters: Ruby 1.9.3 and JRuby 1.7.x share one implementation, whilst Ruby 2.x has a different one.

Stability of ordering is a necessary precondition for using bisection to resolve an ordering dependency (as RSpec can do), should we wish to add that in the future.

Ordering is now implemented by sorting on the 256-bit SHA2 hash of the string representation of the seed plus the index of the scenario. As randomisation takes place before non-matching steps are discarded, stability is maintained.

Fixes #971.

With this change, using the --order=random option with a particular seed
will produce the same order on every Ruby interpreter.

Previously, the random seed would produce consistent results on a given
interpreter, but this could not always be reproduced on another version
of Ruby. This occurred because Array#shuffle is implemented differently
in different interpreters: Ruby 1.9.3 and JRuby 1.7.x share one
implementation, whilst Ruby 2.x has a different one.
In addition to predictability, another useful property of random
ordering is stability, i.e. if a given seed results in the order BCDA,
then skipping a step will not affect the relative order of the other
steps: if C is skipped, the order should be BDA. This is a necessary
precondition for bisection, should we wish to add that in the future.

As randomisation takes place before filtering we get stability for free.
This change just documents it and preserves it from future regression.
@danascheider
Copy link
Contributor

Looks good @threedaymonk, thanks!

@danascheider danascheider merged commit 44756b9 into cucumber:master May 15, 2016
@brasmusson
Copy link
Contributor

@danascheider Do not forget to update the History.md, when you merge a PR (this PR, and issue #971 that it closes, needs to be mentioned there now).

@danascheider
Copy link
Contributor

Sorry, will do!

@mattwynne
Copy link
Member

I often forget too. It's a hassle but I think it's well worth it. I just wish there was some automatic way of doing it...

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Seeded order is platform-dependent
4 participants