github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/xtest/context.go (about) 1 package xtest 2 3 import ( 4 "context" 5 "runtime/pprof" 6 "testing" 7 8 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" 9 ) 10 11 func Context(t testing.TB) context.Context { 12 ctx, cancel := xcontext.WithCancel(context.Background()) 13 ctx = pprof.WithLabels(ctx, pprof.Labels("test", t.Name())) 14 pprof.SetGoroutineLabels(ctx) 15 16 t.Cleanup(func() { 17 pprof.SetGoroutineLabels(ctx) 18 cancel() 19 }) 20 21 return ctx 22 } 23 24 func ContextWithCommonTimeout(ctx context.Context, t testing.TB) context.Context { 25 if ctx.Done() == nil { 26 t.Fatal("Use context with timeout only with context, cancelled on finish test, for example xtest.Context") 27 } 28 29 ctx, ctxCancel := xcontext.WithTimeout(ctx, commonWaitTimeout) 30 _ = ctxCancel // suppress linters, it is ok for leak for small amount of time: it will cancel by parent context 31 32 return ctx 33 }