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.go59
1 files changed, 57 insertions, 2 deletions
diff --git a/src/context/context_test.go b/src/context/context_test.go
index eb5a86b3c6..5311d8d4f4 100644
--- a/src/context/context_test.go
+++ b/src/context/context_test.go
@@ -793,8 +793,11 @@ func XTestCustomContextGoroutines(t testingT) {
func XTestCause(t testingT) {
var (
- parentCause = fmt.Errorf("parentCause")
- childCause = fmt.Errorf("childCause")
+ forever = 1e6 * time.Second
+ parentCause = fmt.Errorf("parentCause")
+ childCause = fmt.Errorf("childCause")
+ tooSlow = fmt.Errorf("tooSlow")
+ finishedEarly = fmt.Errorf("finishedEarly")
)
for _, test := range []struct {
name string
@@ -926,6 +929,58 @@ func XTestCause(t testingT) {
err: DeadlineExceeded,
cause: DeadlineExceeded,
},
+ {
+ name: "WithTimeout canceled",
+ ctx: func() Context {
+ ctx, cancel := WithTimeout(Background(), forever)
+ cancel()
+ return ctx
+ }(),
+ err: Canceled,
+ cause: Canceled,
+ },
+ {
+ name: "WithTimeoutCause",
+ ctx: func() Context {
+ ctx, cancel := WithTimeoutCause(Background(), 0, tooSlow)
+ cancel()
+ return ctx
+ }(),
+ err: DeadlineExceeded,
+ cause: tooSlow,
+ },
+ {
+ name: "WithTimeoutCause canceled",
+ ctx: func() Context {
+ ctx, cancel := WithTimeoutCause(Background(), forever, tooSlow)
+ cancel()
+ return ctx
+ }(),
+ err: Canceled,
+ cause: Canceled,
+ },
+ {
+ name: "WithTimeoutCause stacked",
+ ctx: func() Context {
+ ctx, cancel := WithCancelCause(Background())
+ ctx, _ = WithTimeoutCause(ctx, 0, tooSlow)
+ cancel(finishedEarly)
+ return ctx
+ }(),
+ err: DeadlineExceeded,
+ cause: tooSlow,
+ },
+ {
+ name: "WithTimeoutCause stacked canceled",
+ ctx: func() Context {
+ ctx, cancel := WithCancelCause(Background())
+ ctx, _ = WithTimeoutCause(ctx, forever, tooSlow)
+ cancel(finishedEarly)
+ return ctx
+ }(),
+ err: Canceled,
+ cause: finishedEarly,
+ },
} {
if got, want := test.ctx.Err(), test.err; want != got {
t.Errorf("%s: ctx.Err() = %v want %v", test.name, got, want)