Skip to content

Instantly share code, notes, and snippets.

@gonzaloserrano
Created April 6, 2016 14:09
Show Gist options
  • Save gonzaloserrano/ef74bc12e3ccd8995897fbeaa8026a59 to your computer and use it in GitHub Desktop.
Save gonzaloserrano/ef74bc12e3ccd8995897fbeaa8026a59 to your computer and use it in GitHub Desktop.
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