fix deterministic scenario ordering with feature concurrency

while global rand is concurrent safe, since each suite is handling
picking scenario order on it’s own, if running features under
concurrency we cannot guarantee the order Features will execute under,
therefore we have each suite initialize its own randomness Source with
the initial seed, such that their random order selection within a
Feature should always be deterministic when given a specific seed.
Этот коммит содержится в:
Matthew Rothenberg 2017-04-25 12:33:20 -04:00
родитель 0eed963c63
коммит cf6160b3f2
2 изменённых файлов: 2 добавлений и 5 удалений

4
run.go
Просмотреть файл

@ -118,10 +118,6 @@ func RunWithOptions(suite string, contextInitializer func(suite *Suite), opt Opt
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
seed = r.Int63n(99998) + 1
}
if seed != 0 {
// init global rand module (concurrent safe) with our seed
rand.Seed(seed)
}
r := runner{
fmt: formatter(suite, output),

Просмотреть файл

@ -337,7 +337,8 @@ func (s *Suite) runFeature(f *feature) {
// then shuffle it if we are randomizing scenarios
scenarios := make([]interface{}, len(f.ScenarioDefinitions))
if s.randomSeed != 0 {
perm := rand.Perm(len(f.ScenarioDefinitions))
r := rand.New(rand.NewSource(s.randomSeed))
perm := r.Perm(len(f.ScenarioDefinitions))
for i, v := range perm {
scenarios[v] = f.ScenarioDefinitions[i]
}