Browse Source

context: deflake tests under Go 1.6

The context tests were flaky under Go 1.6 on Windows. Make them
slower, but make up for the slowness by parallelizing them.

These tests don't run on Go 1.7+ in the subrepo. They were deflaked in
the standard library's context in Go 1.7.

Updates golang/go#11811

Change-Id: I8dc8d9e13e72e87b4444e92d2316dd95bd7d066d
Reviewed-on: https://go-review.googlesource.com/34288
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Brad Fitzpatrick 9 years ago
parent
commit
cfae461ced
1 changed files with 23 additions and 17 deletions
  1. 23 17
      context/context_test.go

+ 23 - 17
context/context_test.go

@@ -243,45 +243,51 @@ func testDeadline(c Context, wait time.Duration, t *testing.T) {
 }
 }
 
 
 func TestDeadline(t *testing.T) {
 func TestDeadline(t *testing.T) {
-	c, _ := WithDeadline(Background(), time.Now().Add(100*time.Millisecond))
+	t.Parallel()
+	const timeUnit = 500 * time.Millisecond
+	c, _ := WithDeadline(Background(), time.Now().Add(1*timeUnit))
 	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
 	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
 		t.Errorf("c.String() = %q want prefix %q", got, prefix)
 		t.Errorf("c.String() = %q want prefix %q", got, prefix)
 	}
 	}
-	testDeadline(c, 200*time.Millisecond, t)
+	testDeadline(c, 2*timeUnit, t)
 
 
-	c, _ = WithDeadline(Background(), time.Now().Add(100*time.Millisecond))
+	c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit))
 	o := otherContext{c}
 	o := otherContext{c}
-	testDeadline(o, 200*time.Millisecond, t)
+	testDeadline(o, 2*timeUnit, t)
 
 
-	c, _ = WithDeadline(Background(), time.Now().Add(100*time.Millisecond))
+	c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit))
 	o = otherContext{c}
 	o = otherContext{c}
-	c, _ = WithDeadline(o, time.Now().Add(300*time.Millisecond))
-	testDeadline(c, 200*time.Millisecond, t)
+	c, _ = WithDeadline(o, time.Now().Add(3*timeUnit))
+	testDeadline(c, 2*timeUnit, t)
 }
 }
 
 
 func TestTimeout(t *testing.T) {
 func TestTimeout(t *testing.T) {
-	c, _ := WithTimeout(Background(), 100*time.Millisecond)
+	t.Parallel()
+	const timeUnit = 500 * time.Millisecond
+	c, _ := WithTimeout(Background(), 1*timeUnit)
 	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
 	if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) {
 		t.Errorf("c.String() = %q want prefix %q", got, prefix)
 		t.Errorf("c.String() = %q want prefix %q", got, prefix)
 	}
 	}
-	testDeadline(c, 200*time.Millisecond, t)
+	testDeadline(c, 2*timeUnit, t)
 
 
-	c, _ = WithTimeout(Background(), 100*time.Millisecond)
+	c, _ = WithTimeout(Background(), 1*timeUnit)
 	o := otherContext{c}
 	o := otherContext{c}
-	testDeadline(o, 200*time.Millisecond, t)
+	testDeadline(o, 2*timeUnit, t)
 
 
-	c, _ = WithTimeout(Background(), 100*time.Millisecond)
+	c, _ = WithTimeout(Background(), 1*timeUnit)
 	o = otherContext{c}
 	o = otherContext{c}
-	c, _ = WithTimeout(o, 300*time.Millisecond)
-	testDeadline(c, 200*time.Millisecond, t)
+	c, _ = WithTimeout(o, 3*timeUnit)
+	testDeadline(c, 2*timeUnit, t)
 }
 }
 
 
 func TestCanceledTimeout(t *testing.T) {
 func TestCanceledTimeout(t *testing.T) {
-	c, _ := WithTimeout(Background(), 200*time.Millisecond)
+	t.Parallel()
+	const timeUnit = 500 * time.Millisecond
+	c, _ := WithTimeout(Background(), 2*timeUnit)
 	o := otherContext{c}
 	o := otherContext{c}
-	c, cancel := WithTimeout(o, 400*time.Millisecond)
+	c, cancel := WithTimeout(o, 4*timeUnit)
 	cancel()
 	cancel()
-	time.Sleep(100 * time.Millisecond) // let cancelation propagate
+	time.Sleep(1 * timeUnit) // let cancelation propagate
 	select {
 	select {
 	case <-c.Done():
 	case <-c.Done():
 	default:
 	default: