Skip to content

Commit bec24bd

Browse files
committed
Replace time.Sleep with channel using time.After
1 parent 7484d21 commit bec24bd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/resolver/dns/dns_resolver_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,19 @@ func (s) TestMinResolutionInterval_NoExtraDelay(t *testing.T) {
13261326
// test duration. This number is sufficiently large to validate the
13271327
// behavior across multiple resolution attempts, while also reducing
13281328
// the likelihood of flakiness due to timing issues.
1329-
for i := 0; i < 4; i++ {
1329+
for i := 1; i <= 4; i++ {
13301330
verifyUpdateFromResolver(ctx, t, stateCh, wantAddrs, nil, wantSC)
1331-
time.Sleep(1 * time.Second) // respect resolution rate of 1 second for re-resolve
1331+
1332+
// Wait for 1 second to respect [MinResolutionInterval]
1333+
// before sending another resolution request
1334+
select {
1335+
case <-dnsinternal.TimeAfterFunc(1 * time.Second):
1336+
// Waited for 1 second
1337+
case <-ctx.Done():
1338+
// If the context is done, exit the loop
1339+
t.Fatal("Timeout when waiting for a state update from the resolver")
1340+
}
1341+
13321342
r.ResolveNow(resolver.ResolveNowOptions{})
13331343
}
13341344
}

0 commit comments

Comments
 (0)