From 3b0ffe413f36eb2ddb6f104e35f40e40948b02f4 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 16 Oct 2020 09:10:36 +0200 Subject: [PATCH] tests: reduce timeouts and iterations (#1175) This reduces the time it takes to run the test. Shorter timeouts on clients to avoid awaiting for the detault timeouts. It's also reduces the iterations in some test functions, this doesn't seem to impact the tests indicating those numbers where random to begin with. Use shorter crypto keys, as we don't need to strength in tests. Stop using Google Public DNS and other remotes in tests as well: it's faster, keeps things local and avoids spilling info to Google. This brings the test duration down from ~8s to ~2s on my machine, a 4x reduction. ~~~ PASS ok github.com/miekg/dns 2.046s Switched to branch 'master' Your branch is up-to-date with 'origin/master'. PASS ok github.com/miekg/dns 7.915s ~~~ Signed-off-by: Miek Gieben --- dnssec_test.go | 4 ++-- issue_test.go | 18 ------------------ parse_test.go | 4 ++-- remote_test.go | 19 ------------------- server_test.go | 7 ++++--- sig0_test.go | 4 +++- 6 files changed, 11 insertions(+), 45 deletions(-) delete mode 100644 remote_test.go diff --git a/dnssec_test.go b/dnssec_test.go index 32c195d2..a43afeba 100644 --- a/dnssec_test.go +++ b/dnssec_test.go @@ -168,7 +168,7 @@ func Test65534(t *testing.T) { key.Flags = 256 key.Protocol = 3 key.Algorithm = RSASHA256 - privkey, _ := key.Generate(1024) + privkey, _ := key.Generate(512) sig := new(RRSIG) sig.Hdr = RR_Header{"miek.nl.", TypeRRSIG, ClassINET, 14400, 0} @@ -251,7 +251,7 @@ func TestKeyRSA(t *testing.T) { key.Flags = 256 key.Protocol = 3 key.Algorithm = RSASHA256 - priv, _ := key.Generate(2048) + priv, _ := key.Generate(512) soa := new(SOA) soa.Hdr = RR_Header{"miek.nl.", TypeSOA, ClassINET, 14400, 0} diff --git a/issue_test.go b/issue_test.go index 7299d314..c7b19f34 100644 --- a/issue_test.go +++ b/issue_test.go @@ -7,24 +7,6 @@ import ( "testing" ) -func TestTCPRtt(t *testing.T) { - m := new(Msg) - m.RecursionDesired = true - m.SetQuestion("example.org.", TypeA) - - c := &Client{} - for _, proto := range []string{"udp", "tcp"} { - c.Net = proto - _, rtt, err := c.Exchange(m, "8.8.4.4:53") - if err != nil { - t.Fatal(err) - } - if rtt == 0 { - t.Fatalf("expecting non zero rtt %s, got zero", c.Net) - } - } -} - func TestNSEC3MissingSalt(t *testing.T) { rr := testRR("ji6neoaepv8b5o6k4ev33abha8ht9fgc.example. NSEC3 1 1 12 aabbccdd K8UDEMVP1J2F7EG6JEBPS17VP3N8I58H") m := new(Msg) diff --git a/parse_test.go b/parse_test.go index 272da6cd..d839562a 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1312,8 +1312,8 @@ func TestNewPrivateKey(t *testing.T) { algorithms := []algorithm{ {ECDSAP256SHA256, 256}, {ECDSAP384SHA384, 384}, - {RSASHA1, 1024}, - {RSASHA256, 2048}, + {RSASHA1, 512}, + {RSASHA256, 512}, {ED25519, 256}, } diff --git a/remote_test.go b/remote_test.go deleted file mode 100644 index 4cf701fe..00000000 --- a/remote_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package dns - -import "testing" - -const LinodeAddr = "176.58.119.54:53" - -func TestClientRemote(t *testing.T) { - m := new(Msg) - m.SetQuestion("go.dns.miek.nl.", TypeTXT) - - c := new(Client) - r, _, err := c.Exchange(m, LinodeAddr) - if err != nil { - t.Errorf("failed to exchange: %v", err) - } - if r != nil && r.Rcode != RcodeSuccess { - t.Errorf("failed to get an valid answer\n%v", r) - } -} diff --git a/server_test.go b/server_test.go index 15a3bc85..864b52f5 100644 --- a/server_test.go +++ b/server_test.go @@ -635,7 +635,8 @@ func TestServingResponse(t *testing.T) { if err != nil { t.Fatal("failed to exchange", err) } - m.Response = true + m.Response = true // this holds up the reply, set short read time out to avoid waiting too long + c.ReadTimeout = 100 * time.Millisecond _, _, err = c.Exchange(m, addrstr) if err == nil { t.Fatal("exchanged response message") @@ -668,7 +669,7 @@ func init() { } func checkInProgressQueriesAtShutdownServer(t *testing.T, srv *Server, addr string, client *Client) { - const requests = 100 + const requests = 15 // enough to make this interesting? TODO: find a proper value var errOnce sync.Once // t.Fail will panic if it's called after the test function has @@ -698,7 +699,7 @@ func checkInProgressQueriesAtShutdownServer(t *testing.T, srv *Server, addr stri }) defer HandleRemove("example.com.") - client.Timeout = 10 * time.Second + client.Timeout = 1 * time.Second conns := make([]*Conn, requests) eg := new(errgroup.Group) diff --git a/sig0_test.go b/sig0_test.go index 122de6a8..1abdc4af 100644 --- a/sig0_test.go +++ b/sig0_test.go @@ -19,12 +19,14 @@ func TestSIG0(t *testing.T) { keyrr.Hdr.Rrtype = TypeKEY keyrr.Hdr.Class = ClassINET keyrr.Algorithm = alg - keysize := 1024 + keysize := 512 switch alg { case ECDSAP256SHA256: keysize = 256 case ECDSAP384SHA384: keysize = 384 + case RSASHA512: + keysize = 1024 } pk, err := keyrr.Generate(keysize) if err != nil {