Fix a flaky test by not depending on Google (#2565)
TestLookupAutoPathErratic sometimes fail on TravisCI saying below ``` === RUN TestLookupAutoPathErratic --- FAIL: TestLookupAutoPathErratic (8.30s) erratic_autopath_test.go:39: Test 0, failed to sent query: "read udp [::1]:39758->[::1]:56643: i/o timeout" FAIL ``` The failure happens when Google replies slowly. This PR changes to not use Google but run CoreDNS locally and proxy to the server. --- Because the failure depends on Google, sometimes it happens frequently but sometimes it doesn't happen. I hope following test help you reproduce it. ``` func TestLookupAutoPathErratic2(t *testing.T) { for i := 0; i < 200; i++ { TestLookupAutoPathErratic(t) } } ``` or I can reproduce it by changing proxy to other DNS like 1.1.1.1 instead of 8.8.8.8 too
This commit is contained in:
parent
d42d80c4f6
commit
643dfd7419
1 changed files with 90 additions and 50 deletions
|
@ -1,16 +1,53 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func setupProxyTargetCoreDNS(t *testing.T, fn func(string)) {
|
||||
tmpdir, err := ioutil.TempDir(os.TempDir(), "coredns")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
content := `
|
||||
example.org. IN SOA sns.dns.icann.org. noc.dns.icann.org. 1 3600 3600 3600 3600
|
||||
|
||||
google.com. IN SOA ns1.google.com. dns-admin.google.com. 1 3600 3600 3600 3600
|
||||
google.com. IN A 172.217.25.110
|
||||
`
|
||||
|
||||
path := filepath.Join(tmpdir, "file")
|
||||
if err = ioutil.WriteFile(path, []byte(content), 0644); err != nil {
|
||||
t.Fatalf("Could not write to temp file: %s", err)
|
||||
}
|
||||
defer os.Remove(path)
|
||||
|
||||
corefile := `.:0 {
|
||||
file ` + path + `
|
||||
}
|
||||
`
|
||||
i, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get proxy target CoreDNS serving instance: %s", err)
|
||||
}
|
||||
defer i.Stop()
|
||||
|
||||
fn(udp)
|
||||
}
|
||||
|
||||
func TestLookupAutoPathErratic(t *testing.T) {
|
||||
setupProxyTargetCoreDNS(t, func(proxyPath string) {
|
||||
corefile := `.:0 {
|
||||
erratic
|
||||
autopath @erratic
|
||||
proxy . 8.8.8.8:53
|
||||
proxy . ` + proxyPath + `
|
||||
debug
|
||||
}
|
||||
`
|
||||
|
@ -48,12 +85,14 @@ func TestLookupAutoPathErratic(t *testing.T) {
|
|||
t.Fatalf("Test %d, expected answer type %d, got %d", i, tc.expectedType, x)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAutoPathErraticNotLoaded(t *testing.T) {
|
||||
setupProxyTargetCoreDNS(t, func(proxyPath string) {
|
||||
corefile := `.:0 {
|
||||
autopath @erratic
|
||||
proxy . 8.8.8.8:53
|
||||
proxy . ` + proxyPath + `
|
||||
debug
|
||||
}
|
||||
`
|
||||
|
@ -77,4 +116,5 @@ func TestAutoPathErraticNotLoaded(t *testing.T) {
|
|||
if r.Rcode != dns.RcodeNameError {
|
||||
t.Fatalf("Expected NXDOMAIN, got %d", r.Rcode)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue