Created
April 6, 2016 14:09
-
-
Save gonzaloserrano/ef74bc12e3ccd8995897fbeaa8026a59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
"time" | |
"golang.org/x/net/context" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestContext(t *testing.T) { | |
assert := assert.New(t) | |
ctx := context.Background() | |
contextWithCancel, cancel := context.WithCancel(ctx) | |
cancel() | |
select { | |
case <-ctx.Done(): | |
println("parent") | |
assert.True(true) | |
case <-contextWithCancel.Done(): | |
println("child") | |
assert.True(true) | |
case <-time.After(time.Second): | |
t.Error("timeout") | |
t.Fail() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment