Skip to content

Commit

Permalink
Set a deterministic seed for random sort index
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jul 24, 2017
1 parent 2ab704c commit e51ccb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def run(index_class, context)
it test_case.name do
resolve = lambda do
index = index_class.new(test_case.index.specs)
index.rng = Random.new(test_case.name.size * 5 + 7) if index.respond_to?(:rng=)
resolver = Resolver.new(index, TestUI.new)
resolver.resolve(test_case.requested, test_case.base)
end
Expand Down
11 changes: 9 additions & 2 deletions spec/spec_helper/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ def sort_dependencies(*)
end

class RandomSortIndex < TestIndex
def sort_dependencies(dependencies, _activated, _conflicts)
dependencies.shuffle
attr_writer :rng
def rng
@rng ||= Random.new
end

if RUBY_VERSION >= "2.4"
def sort_dependencies(dependencies, _activated, _conflicts)
dependencies.shuffle(random: rng)
end
end
end

Expand Down

0 comments on commit e51ccb0

Please sign in to comment.