From c3c0d2e42f3913b64463f13fb63a5e0a78bed627 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 6 Mar 2025 15:49:34 +0400 Subject: [PATCH] test: fix dns test in race mode This is a workaround, as using `t.Context()` causes panics as `t.Log` is used after the test finishes, this is related to unsynchronized context.AfterFunc, but I will leave the fix to @DmitryMV. Signed-off-by: Andrey Smirnov --- internal/pkg/dns/dns_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/pkg/dns/dns_test.go b/internal/pkg/dns/dns_test.go index 4d90e0cbf..238b705ca 100644 --- a/internal/pkg/dns/dns_test.go +++ b/internal/pkg/dns/dns_test.go @@ -128,9 +128,9 @@ func TestGC_NOGC(t *testing.T) { t.Run(name, func(t *testing.T) { m := dns.NewManager(&testReader{}, func(e suture.Event) { t.Log("dns-runners event:", e) }, zaptest.NewLogger(t)) - m.ServeBackground(t.Context()) - m.ServeBackground(t.Context()) - require.Panics(t, func() { m.ServeBackground(context.Background()) }) //nolint:usetesting // need background context to trigger panic + m.ServeBackground(context.Background()) //nolint:usetesting + m.ServeBackground(context.Background()) //nolint:usetesting + require.Panics(t, func() { m.ServeBackground(context.TODO()) }) //nolint:usetesting for _, err := range m.RunAll(slices.Values([]dns.AddressPair{ {Network: "udp", Addr: netip.MustParseAddrPort("127.0.0.1:10700")}, @@ -172,7 +172,7 @@ func newManager(t *testing.T, nameservers ...string) func() { return p }) - ctx, cancel := context.WithCancel(t.Context()) + ctx, cancel := context.WithCancel(context.Background()) //nolint:usetesting t.Cleanup(cancel) m.SetUpstreams(slices.Values(pxs))