diff options
author | 2021-06-10 04:49:31 -0400 | |
---|---|---|
committer | 2021-06-10 10:49:31 +0200 | |
commit | 79d67953332441fbfce8f8444a2a748283ae2513 (patch) | |
tree | 217aeedd100cc75be76ef1ce46ad2348fcdac4d5 /test | |
parent | ad7ccf6925bdaa9074d568d6b36209e74283b0bb (diff) | |
download | coredns-79d67953332441fbfce8f8444a2a748283ae2513.tar.gz coredns-79d67953332441fbfce8f8444a2a748283ae2513.tar.zst coredns-79d67953332441fbfce8f8444a2a748283ae2513.zip |
plugin/secondary: Retry initial transfer until successful (#4663)
* retry initial transfer
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* fix import grouping
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* add test; use backoff timeout
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* fix import order
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* manual backoff
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/secondary_test.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/secondary_test.go b/test/secondary_test.go index c6b311be9..c60aa0355 100644 --- a/test/secondary_test.go +++ b/test/secondary_test.go @@ -132,3 +132,87 @@ func TestIxfrResponse(t *testing.T) { t.Fatalf("Serial should be %d, got %d", 2015082541, soa.Serial) } } + +func TestRetryInitialTransfer(t *testing.T) { + // Start up a secondary that expects to transfer from a master that doesn't exist yet + corefile := `example.org:0 { + secondary { + transfer from 127.0.0.1:5399 + } + }` + + i, udp, _, err := CoreDNSServerAndPorts(corefile) + if err != nil { + t.Fatalf("Could not get CoreDNS serving instance: %s", err) + } + defer i.Stop() + + m := new(dns.Msg) + m.SetQuestion("www.example.org.", dns.TypeA) + resp, err := dns.Exchange(m, udp) + if err != nil { + t.Fatal("Expected to receive reply, but didn't") + } + // Expect that the query will fail + if resp.Rcode != dns.RcodeServerFailure { + t.Fatalf("Expected reply to be a SERVFAIL, got %d", resp.Rcode) + } + + // Now spin up the master server + name, rm, err := test.TempFile(".", `$ORIGIN example.org. +@ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( + 2017042745 ; serial + 7200 ; refresh (2 hours) + 3600 ; retry (1 hour) + 1209600 ; expire (2 weeks) + 3600 ; minimum (1 hour) +) + + 3600 IN NS a.iana-servers.net. + 3600 IN NS b.iana-servers.net. + +www IN A 127.0.0.1 +www IN AAAA ::1 +`) + if err != nil { + t.Fatalf("Failed to create zone: %s", err) + } + defer rm() + + corefileMaster := `example.org:5399 { + file ` + name + ` + transfer { + to * + } + }` + + master, _, _, err := CoreDNSServerAndPorts(corefileMaster) + if err != nil { + t.Fatalf("Could not start CoreDNS master: %s", err) + } + defer master.Stop() + + retry := time.Tick(time.Millisecond * 100) + timeout := time.Tick(time.Second * 5) + + for { + select { + case <-retry: + m = new(dns.Msg) + m.SetQuestion("www.example.org.", dns.TypeA) + resp, err = dns.Exchange(m, udp) + if err != nil { + continue + } + // Expect the query to succeed + if resp.Rcode != dns.RcodeSuccess { + continue + } + return + case <-timeout: + t.Fatal("Timed out trying for successful response.") + return + } + } + +} |