diff options
author | Jaana Burcu Dogan <jbd@google.com> | 2016-08-19 11:13:11 -0700 |
---|---|---|
committer | Jaana Burcu Dogan <jbd@google.com> | 2016-08-19 20:25:12 +0000 |
commit | ab9137dd24e10a9f884475413437cc31e48dbdf7 (patch) | |
tree | a830bf08767251df41aca9c366d44a0232819c86 /src/context | |
parent | 3de7dbb19145dcc6b7db8da7aef695961dbb5ece (diff) | |
download | go-ab9137dd24e10a9f884475413437cc31e48dbdf7.tar.gz go-ab9137dd24e10a9f884475413437cc31e48dbdf7.zip |
context: test WithCancel with canceled parent
Change-Id: I32079cc12cfffb8520f0073a8b5119705dc0cd1b
Reviewed-on: https://go-review.googlesource.com/27401
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/context')
-rw-r--r-- | src/context/context_test.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/context/context_test.go b/src/context/context_test.go index cf182110fb..c31c4d8718 100644 --- a/src/context/context_test.go +++ b/src/context/context_test.go @@ -584,6 +584,21 @@ func TestCancelRemoves(t *testing.T) { checkChildren("after cancelling WithTimeout child", ctx, 0) } +func TestWithCancelCanceledParent(t *testing.T) { + parent, pcancel := WithCancel(Background()) + pcancel() + + c, _ := WithCancel(parent) + select { + case <-c.Done(): + case <-time.After(5 * time.Second): + t.Fatal("timeout waiting for Done") + } + if got, want := c.Err(), Canceled; got != want { + t.Errorf("child not cancelled; got = %v, want = %v", got, want) + } +} + func TestWithValueChecksKey(t *testing.T) { panicVal := recoveredValue(func() { WithValue(Background(), []byte("foo"), "bar") }) if panicVal == nil { |