Browse Source

go.net/context: adjust TestAlloc so it passes on windows

Do not assume that a particular code path is selected
in WithTimeout.

Also Windows cannot wait for less then 15 millisecond,
so use that instead of 1 nanosecond in test. Otherwise
test takes too long while it looks like it is quick.

Fixes golang/go#8033.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/103470044
Alex Brainman 11 years ago
parent
commit
6b9623cc97
1 changed files with 4 additions and 4 deletions
  1. 4 4
      context/context_test.go

+ 4 - 4
context/context_test.go

@@ -310,12 +310,12 @@ func TestAllocs(t *testing.T) {
 			gccgoLimit: 3,
 		},
 		{
-			desc: "WithTimeout(bg, 1*time.Nanosecond)",
+			desc: "WithTimeout(bg, 15*time.Millisecond)",
 			f: func() {
-				c, _ := WithTimeout(bg, 1*time.Nanosecond)
+				c, _ := WithTimeout(bg, 15*time.Millisecond)
 				<-c.Done()
 			},
-			limit:      7,
+			limit:      9,
 			gccgoLimit: 13,
 		},
 		{
@@ -345,7 +345,7 @@ func TestAllocs(t *testing.T) {
 			// TOOD(iant): Remove this when gccgo does do escape analysis.
 			limit = test.gccgoLimit
 		}
-		if n := testing.AllocsPerRun(1000, test.f); n > limit {
+		if n := testing.AllocsPerRun(100, test.f); n > limit {
 			t.Errorf("%s allocs = %f want %d", test.desc, n, int(limit))
 		}
 	}