diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2014-09-12 16:16:09 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2014-09-12 16:16:09 -0700 |
| commit | d6cd230c985b5216ea6059ab69738c59658801ae (patch) | |
| tree | f4814f628bfdaa4bc68eca171125f47cd150c109 /src/runtime/map_test.go | |
| parent | d78823168fb90c33b6a208e56bffa1e17e32de59 (diff) | |
| download | go-d6cd230c985b5216ea6059ab69738c59658801ae.tar.xz | |
runtime: test iteration order of sparse maps
The behavior was fixed in CL 141270043. Add a test.
Fixes #8410.
LGTM=khr
R=khr, remyoudompheng
CC=golang-codereviews
https://golang.org/cl/137560044
Diffstat (limited to 'src/runtime/map_test.go')
| -rw-r--r-- | src/runtime/map_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/runtime/map_test.go b/src/runtime/map_test.go index e2f1481ad5..9b76a5bbf2 100644 --- a/src/runtime/map_test.go +++ b/src/runtime/map_test.go @@ -442,6 +442,41 @@ func TestMapIterOrder(t *testing.T) { } } +// Issue 8410 +func TestMapSparseIterOrder(t *testing.T) { + // Run several rounds to increase the probability + // of failure. One is not enough. +NextRound: + for round := 0; round < 10; round++ { + m := make(map[int]bool) + // Add 1000 items, remove 980. + for i := 0; i < 1000; i++ { + m[i] = true + } + for i := 20; i < 1000; i++ { + delete(m, i) + } + + var first []int + for i := range m { + first = append(first, i) + } + + // 80 chances to get a different iteration order. + for n := 0; n < 80; n++ { + idx := 0 + for i := range m { + if i != first[idx] { + // iteration order changed. + continue NextRound + } + idx++ + } + } + t.Fatalf("constant iteration order on round %d: %v", round, first) + } +} + func TestMapStringBytesLookup(t *testing.T) { // Use large string keys to avoid small-allocation coalescing, // which can cause AllocsPerRun to report lower counts than it should. |
