Update ddns_test.go

This commit is contained in:
77-QiQi authored and GitHub committed 2026-09-14 11:06:44 +08:00
1 parent 39e1c6d1be
commit fa611ebd9e
1 file changed
+7 -5
+7 -5
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"net" "net"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"github.com/libdns/libdns" "github.com/libdns/libdns"
@@ -208,10 +209,10 @@ func TestIndependentDualStackProcessing(t *testing.T) {
} }
func TestTransientSOAFailureAndRetry(t *testing.T) { func TestTransientSOAFailureAndRetry(t *testing.T) {
attempts := 0 var attempts int64
handler := dns.NewServeMux() handler := dns.NewServeMux()
handler.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) { handler.HandleFunc(".", func(w dns.ResponseWriter, r *dns.Msg) {
attempts++ atomic.AddInt64(&attempts, 1)
m := new(dns.Msg) m := new(dns.Msg)
m.SetReply(r) m.SetReply(r)
_ = w.WriteMsg(m) _ = w.WriteMsg(m)
@@ -244,9 +245,10 @@ func TestTransientSOAFailureAndRetry(t *testing.T) {
ctx := context.WithValue(context.Background(), DNSServerKey{}, []string{pc.LocalAddr().String()}) ctx := context.WithValue(context.Background(), DNSServerKey{}, []string{pc.LocalAddr().String()})
provider.UpdateDomain(ctx) provider.UpdateDomain(ctx)
expectedAttempts := int(maxRetries) * 2 actualAttempts := atomic.LoadInt64(&attempts)
if attempts != expectedAttempts { expectedAttempts := int64(maxRetries) * 2
t.Fatalf("expected exact attempt count of %d, got %d", expectedAttempts, attempts) if actualAttempts != expectedAttempts {
t.Fatalf("expected exact attempt count of %d, got %d", expectedAttempts, actualAttempts)
} }
} }