mirror of
https://github.com/golang/go.git
synced 2025-11-10 13:41:05 +00:00
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>
This commit is contained in:
parent
3de7dbb191
commit
ab9137dd24
1 changed files with 15 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue