From e5f57d2cfabae24e7606d8d7cf9eca3e45e05e10 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 1 Jul 2025 15:48:44 +0200 Subject: [PATCH] ktesting: add WithoutCancel This closes a gap compared to the context package. It's useful when combined with Ginkgo to keep something running beyond the end of the Ginkgo BeforeEach or It node. --- test/utils/ktesting/withcontext.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/utils/ktesting/withcontext.go b/test/utils/ktesting/withcontext.go index dcd4a8382d6..6f1ddfa7221 100644 --- a/test/utils/ktesting/withcontext.go +++ b/test/utils/ktesting/withcontext.go @@ -43,6 +43,13 @@ func WithCancel(tCtx TContext) TContext { } } +// WithoutCancel causes the returned context to ignore cancellation of its parent. +func WithoutCancel(tCtx TContext) TContext { + tCtx.Helper() + ctx := context.WithoutCancel(tCtx) + return WithContext(tCtx, ctx) +} + // WithTimeout sets up new context with a timeout. Canceling the timeout gets // registered in a [TContext.Cleanup] callback. [TContext.Cancel] cancels only // the new context. The cause is used as reason why the context is canceled