mirror of https://github.com/status-im/consul.git
Fixed unit tests and updated limits
This commit is contained in:
parent
6e80b6b127
commit
cfa5986df7
|
@ -755,9 +755,9 @@ func (d *DNSServer) trimTCPResponse(req, resp *dns.Msg) (trimmed bool) {
|
||||||
// Beyond 2500 records, performance gets bad
|
// Beyond 2500 records, performance gets bad
|
||||||
// Limit the number of records at once, anyway, it won't fit in 64k
|
// Limit the number of records at once, anyway, it won't fit in 64k
|
||||||
// For SRV Records, the max is around 500 records, for A, less than 2k
|
// For SRV Records, the max is around 500 records, for A, less than 2k
|
||||||
truncateAt := 2048
|
truncateAt := 4096
|
||||||
if req.Question[0].Qtype == dns.TypeSRV {
|
if req.Question[0].Qtype == dns.TypeSRV {
|
||||||
truncateAt = 640
|
truncateAt = 1024
|
||||||
}
|
}
|
||||||
if len(resp.Answer) > truncateAt {
|
if len(resp.Answer) > truncateAt {
|
||||||
resp.Answer = resp.Answer[:truncateAt]
|
resp.Answer = resp.Answer[:truncateAt]
|
||||||
|
|
|
@ -3080,6 +3080,7 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
|
||||||
"tcp",
|
"tcp",
|
||||||
"udp",
|
"udp",
|
||||||
}
|
}
|
||||||
|
for _, maxSize := range []uint16{8192, 65535} {
|
||||||
for _, qType := range []uint16{dns.TypeANY, dns.TypeA, dns.TypeSRV} {
|
for _, qType := range []uint16{dns.TypeANY, dns.TypeA, dns.TypeSRV} {
|
||||||
for _, question := range questions {
|
for _, question := range questions {
|
||||||
for _, protocol := range protocols {
|
for _, protocol := range protocols {
|
||||||
|
@ -3087,23 +3088,28 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
|
||||||
t.Run(fmt.Sprintf("lookup %s %s (qType:=%d) compressed=%v", question, protocol, qType, compress), func(t *testing.T) {
|
t.Run(fmt.Sprintf("lookup %s %s (qType:=%d) compressed=%v", question, protocol, qType, compress), func(t *testing.T) {
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
m.SetQuestion(question, dns.TypeANY)
|
m.SetQuestion(question, dns.TypeANY)
|
||||||
|
maxSz := maxSize
|
||||||
if protocol == "udp" {
|
if protocol == "udp" {
|
||||||
m.SetEdns0(8192, true)
|
maxSz = 8192
|
||||||
}
|
}
|
||||||
|
m.SetEdns0(uint16(maxSz), true)
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
c.Net = protocol
|
c.Net = protocol
|
||||||
m.Compress = compress
|
m.Compress = compress
|
||||||
in, out, err := c.Exchange(m, a.DNSAddr())
|
in, _, err := c.Exchange(m, a.DNSAddr())
|
||||||
if err != nil && err != dns.ErrTruncated {
|
if err != nil && err != dns.ErrTruncated {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
// Check for the truncate bit
|
|
||||||
shouldBeTruncated := numServices > 5000
|
|
||||||
|
|
||||||
if shouldBeTruncated != in.Truncated || len(in.Answer) > 2000 || len(in.Answer) < 1 || in.Len() > 65535 {
|
// Check for the truncate bit
|
||||||
|
buf, err := m.Pack()
|
||||||
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v",
|
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) sz:= %d in %v",
|
||||||
service, question, protocol, numServices, len(in.Answer), out)
|
service, question, protocol, numServices, len(in.Answer), in)
|
||||||
t.Fatalf("Should have truncated:=%v for %s", shouldBeTruncated, info)
|
if err != nil {
|
||||||
|
t.Fatalf("Error while packing: %v ; info:=%s", err, info)
|
||||||
|
}
|
||||||
|
if len(buf) > int(maxSz) {
|
||||||
|
t.Fatalf("len(buf) := %d > maxSz=%d for %v", len(buf), maxSz, info)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3111,6 +3117,7 @@ func TestDNS_TCP_and_UDP_Truncate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDNS_ServiceLookup_Truncate(t *testing.T) {
|
func TestDNS_ServiceLookup_Truncate(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue