diff --git a/client.go b/client.go index 34b50b41..33e4c0fa 100644 --- a/client.go +++ b/client.go @@ -26,6 +26,8 @@ const ( IPv4AndIPv6 = IPv4 | IPv6 // default option ) +var initialQueryInterval = 4 * time.Second + // Client structure encapsulates both IPv4/IPv6 UDP connections. type client struct { ipv4conn *ipv4.PacketConn @@ -371,7 +373,7 @@ func (c *client) periodicQuery(ctx context.Context, params *lookupParams) error } const maxInterval = 60 * time.Second - interval := 4 * time.Second + interval := initialQueryInterval timer := time.NewTimer(interval) defer timer.Stop() for { diff --git a/service_test.go b/service_test.go index 35afe8d5..6bd8bc41 100644 --- a/service_test.go +++ b/service_test.go @@ -143,11 +143,14 @@ func TestSubtype(t *testing.T) { t.Run("ttl", func(t *testing.T) { origTTL := defaultTTL origCleanupFreq := cleanupFreq - defer func() { + origInitialQueryInterval := initialQueryInterval + t.Cleanup(func() { defaultTTL = origTTL cleanupFreq = origCleanupFreq - }() - defaultTTL = 2 // 2 seconds + initialQueryInterval = origInitialQueryInterval + }) + defaultTTL = 1 // 1 second + initialQueryInterval = 100 * time.Millisecond cleanupFreq = 100 * time.Millisecond ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) @@ -160,8 +163,8 @@ func TestSubtype(t *testing.T) { } <-ctx.Done() - if len(entries) != 2 { - t.Fatalf("Expected to have received 2 entries, but got %d", len(entries)) + if len(entries) < 2 { + t.Fatalf("Expected to have received at least 2 entries, but got %d", len(entries)) } res1 := <-entries res2 := <-entries