1234567891011121314151617181920212223242526272829303132 |
- package context_test
- import (
- "context"
- "fmt"
- "testing"
- "time"
- "github.com/wecisecode/util/logger
- )
- func TestContext(t *testing.T) {
- ctx, cancel := context.WithCancelCause(context.Background())
- cancel(fmt.Errorf("%s", "cancel"))
- go func() {
- for {
- select {
- case <-ctx.Done():
- err := ctx.Err()
- if err == context.Canceled {
- err = context.Cause(ctx)
- }
- logger.Info("context done", err)
- default:
- }
- time.Sleep(5 * time.Second)
- }
- }()
- time.Sleep(1 * time.Hour)
- }
|