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 <andrey.smirnov@siderolabs.com>
This commit is contained in:
Andrey Smirnov 2025-03-06 15:49:34 +04:00
parent 17965c32fa
commit c3c0d2e42f
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811

View File

@ -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))