| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | package test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/test" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLargeAXFR(t *testing.T) { | 
					
						
							| 
									
										
											  
											
												Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
  ... ? A few minutes staring didn't reveal wth it is actually testing.
  Making values smaller revealed race conditions in the tests. Remove
  entirely.
* Move many interval values to variables so we can reset them to short
  values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
  rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok  	github.com/coredns/coredns/test	10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok  	github.com/coredns/coredns/test	35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
											
										 
											2020-10-30 10:27:04 +01:00
										 |  |  | 	// Build a zone in text format. It contains 6.4K AAAA RRs. (this number is rather random) | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	var sb strings.Builder | 
					
						
							| 
									
										
											  
											
												Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
  ... ? A few minutes staring didn't reveal wth it is actually testing.
  Making values smaller revealed race conditions in the tests. Remove
  entirely.
* Move many interval values to variables so we can reset them to short
  values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
  rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok  	github.com/coredns/coredns/test	10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok  	github.com/coredns/coredns/test	35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
											
										 
											2020-10-30 10:27:04 +01:00
										 |  |  | 	const numAAAAs = 6553 | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	sb.WriteString("example.com. IN SOA . . 1 60 60 60 60\n") | 
					
						
							|  |  |  | 	sb.WriteString("example.com. IN NS ns.example.\n") | 
					
						
							| 
									
										
										
										
											2025-05-29 03:50:55 +03:00
										 |  |  | 	for i := range numAAAAs { | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 		sb.WriteString(fmt.Sprintf("%d.example.com. IN AAAA 2001:db8::1\n", i)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Setup the zone file and CoreDNS to serve the zone, allowing zone transfer | 
					
						
							|  |  |  | 	name, rm, err := test.TempFile(".", sb.String()) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Failed to create zone: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer rm() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	corefile := `example.com:0 { | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 		file ` + name + ` | 
					
						
							|  |  |  | 		transfer { | 
					
						
							|  |  |  | 			to * | 
					
						
							| 
									
										
										
										
											2020-04-25 14:08:36 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 	// Start server, and send an AXFR query to the TCP port. We set the deadline to prevent the test from hanging. | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	i, _, tcp, 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("example.com.", dns.TypeAXFR) | 
					
						
							|  |  |  | 	co, err := dns.DialTimeout("tcp", tcp, 5*time.Second) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Expected to establish TCP connection, but didn't: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	defer co.Close() | 
					
						
							|  |  |  | 	co.SetWriteDeadline(time.Now().Add(5 * time.Second)) | 
					
						
							|  |  |  | 	err = co.WriteMsg(m) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 		t.Fatalf("Unable to send AXFR/TCP query: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Then send another query on the same connection.  We use this to confirm that multiple outstanding queries won't cause a race. | 
					
						
							|  |  |  | 	m.SetQuestion("0.example.com.", dns.TypeAAAA) | 
					
						
							|  |  |  | 	err = co.WriteMsg(m) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Unable to send AAAA/TCP query: %s", err) | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 	// The AXFR query should be responded first. | 
					
						
							|  |  |  | 	nrr := 0 // total number of transferred RRs | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	for { | 
					
						
							|  |  |  | 		resp, err := co.ReadMsg() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			t.Fatalf("Expected to receive reply, but didn't: %s", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if len(resp.Answer) == 0 { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// First RR should be SOA. | 
					
						
							|  |  |  | 		if nrr == 0 && resp.Answer[0].Header().Rrtype != dns.TypeSOA { | 
					
						
							|  |  |  | 			t.Fatalf("Expected SOA, but got type %d", resp.Answer[0].Header().Rrtype) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		nrr += len(resp.Answer) | 
					
						
							|  |  |  | 		// If we see another SOA at the end of the message, we are done. | 
					
						
							|  |  |  | 		// Note that this check is not enough to detect all invalid responses, but checking those is not the purpose of this test. | 
					
						
							|  |  |  | 		if nrr > 1 && resp.Answer[len(resp.Answer)-1].Header().Rrtype == dns.TypeSOA { | 
					
						
							|  |  |  | 			break | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// On successful completion, 2 SOA, 1 NS, and all AAAAs should have been transferred. | 
					
						
							|  |  |  | 	if nrr != numAAAAs+3 { | 
					
						
							|  |  |  | 		t.Fatalf("Got an unexpected number of RRs: %d", nrr) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 	// The file plugin shouldn't hijack or (yet) close the connection, so the second query should also be responded. | 
					
						
							|  |  |  | 	resp, err := co.ReadMsg() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatalf("Expected to receive reply, but didn't: %s", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if len(resp.Answer) < 1 { | 
					
						
							|  |  |  | 		t.Fatalf("Expected a non-empty answer, but it was empty") | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 	if resp.Answer[len(resp.Answer)-1].Header().Rrtype != dns.TypeAAAA { | 
					
						
							|  |  |  | 		t.Fatalf("Expected a AAAA answer, but it wasn't: type %d", resp.Answer[len(resp.Answer)-1].Header().Rrtype) | 
					
						
							| 
									
										
										
										
											2019-06-29 00:58:07 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |