]> Cypherpunks.ru repositories - gostls13.git/commitdiff
context: test WithCancel with canceled parent
authorJaana Burcu Dogan <jbd@google.com>
Fri, 19 Aug 2016 18:13:11 +0000 (11:13 -0700)
committerJaana Burcu Dogan <jbd@google.com>
Fri, 19 Aug 2016 20:25:12 +0000 (20:25 +0000)
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>

src/context/context_test.go

index cf182110fbdf9b7409b40cfa2efdfe1660c4f248..c31c4d8718d2c6a9771b9ba6bb5a0b33ddda05e3 100644 (file)
@@ -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 {