test: make maplinear iterdelete test less flaky

iterdelete's run time varies; occasionally we get unlucky. To reduce spurious failures, average away some of the variation.

On my machine, 8 of 5000 runs (0.15%) failed before this CL. After this CL, there were no failures after 35,000 runs.

I confirmed that this adjusted test still fails before CL 141270043.

LGTM=khr
R=khr
CC=bradfitz, golang-codereviews
https://golang.org/cl/140610043
This commit is contained in:
Josh Bleecher Snyder 2014-09-15 10:56:37 -07:00
parent e024ed5ca4
commit f197988ca5
1 changed files with 13 additions and 9 deletions

View File

@ -146,15 +146,19 @@ func main() {
// O(n lg n) time. Fortunately, the checkLinear test
// leaves enough wiggle room to include n lg n time
// (it actually tests for O(n^log_2(3)).
checkLinear("iterdelete", 10000, func(n int) {
m := map[int]int{}
for i := 0; i < n; i++ {
m[i] = i
}
for i := 0; i < n; i++ {
for k := range m {
delete(m, k)
break
// To prevent false positives, average away variation
// by doing multiple rounds within a single run.
checkLinear("iterdelete", 2500, func(n int) {
for round := 0; round < 4; round++ {
m := map[int]int{}
for i := 0; i < n; i++ {
m[i] = i
}
for i := 0; i < n; i++ {
for k := range m {
delete(m, k)
break
}
}
}
})