package context_test import ( "context" "fmt" "testing" "time" "git.wecise.com/wecise/common/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) }