aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-05-21 13:35:22 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-05-21 13:56:29 +0200
commitd06aafeef69b6ffb906d7015fe5b24432766a579 (patch)
tree5a3496ad974c1f4f43f79dd96b843869d6516edb
parent1f30020f856c65ba64fd0e7a663b1fb39c27c990 (diff)
prog: fix determinism in resource creation
We chosen a non-deterministic resource in createResource due to map iteration order. This is caught by existing TestDeterminism, but just very infrequently.
-rw-r--r--prog/rand.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/prog/rand.go b/prog/rand.go
index b3d10cf42..8ade1780f 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -401,6 +401,9 @@ func (r *randGen) createResource(s *state, res *ResourceType, dir Dir) (arg Arg,
allres = append(allres, res1...)
}
}
+ sort.SliceStable(allres, func(i, j int) bool {
+ return allres[i].Type().Name() < allres[j].Type().Name()
+ })
if len(allres) != 0 {
// Bingo!
arg := MakeResultArg(res, dir, allres[r.Intn(len(allres))], 0)