aboutsummaryrefslogtreecommitdiff
path: root/src/context/context_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/context/context_test.go')
-rw-r--r--src/context/context_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/context/context_test.go b/src/context/context_test.go
index 593a7b1521..eb5a86b3c6 100644
--- a/src/context/context_test.go
+++ b/src/context/context_test.go
@@ -5,6 +5,7 @@
package context
import (
+ "errors"
"fmt"
"math/rand"
"runtime"
@@ -934,3 +935,22 @@ func XTestCause(t testingT) {
}
}
}
+
+func XTestCauseRace(t testingT) {
+ cause := errors.New("TestCauseRace")
+ ctx, cancel := WithCancelCause(Background())
+ go func() {
+ cancel(cause)
+ }()
+ for {
+ // Poll Cause, rather than waiting for Done, to test that
+ // access to the underlying cause is synchronized properly.
+ if err := Cause(ctx); err != nil {
+ if err != cause {
+ t.Errorf("Cause returned %v, want %v", err, cause)
+ }
+ break
+ }
+ runtime.Gosched()
+ }
+}