Run new test in parallel

This commit is contained in:
Pierre Souchay 2018-04-17 10:36:12 +02:00
parent e95c510948
commit 6706ff9f0b
1 changed files with 24 additions and 21 deletions

View File

@ -2984,6 +2984,7 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) {
} }
func TestBinarySearch(t *testing.T) { func TestBinarySearch(t *testing.T) {
t.Parallel()
msgSrc := new(dns.Msg) msgSrc := new(dns.Msg)
msgSrc.Compress = true msgSrc.Compress = true
msgSrc.SetQuestion("redis.service.consul.", dns.TypeSRV) msgSrc.SetQuestion("redis.service.consul.", dns.TypeSRV)
@ -2994,27 +2995,29 @@ func TestBinarySearch(t *testing.T) {
msgSrc.Extra = append(msgSrc.Extra, &dns.CNAME{Hdr: dns.RR_Header{Name: target, Class: 1, Rrtype: dns.TypeCNAME, Ttl: 0x3c}, Target: fmt.Sprintf("fx.168.%d.%d.", i/256, i%256)}) msgSrc.Extra = append(msgSrc.Extra, &dns.CNAME{Hdr: dns.RR_Header{Name: target, Class: 1, Rrtype: dns.TypeCNAME, Ttl: 0x3c}, Target: fmt.Sprintf("fx.168.%d.%d.", i/256, i%256)})
} }
for idx, maxSize := range []int{12, 256, 512, 8192, 65535} { for idx, maxSize := range []int{12, 256, 512, 8192, 65535} {
msg := new(dns.Msg) t.Run(fmt.Sprintf("binarySearch %d", maxSize), func(t *testing.T) {
msgSrc.Compress = true msg := new(dns.Msg)
msgSrc.SetQuestion("redis.service.consul.", dns.TypeSRV) msgSrc.Compress = true
msg.Answer = msgSrc.Answer msgSrc.SetQuestion("redis.service.consul.", dns.TypeSRV)
msg.Extra = msgSrc.Extra msg.Answer = msgSrc.Answer
index := make(map[string]dns.RR, len(msg.Extra)) msg.Extra = msgSrc.Extra
indexRRs(msg.Extra, index) index := make(map[string]dns.RR, len(msg.Extra))
blen := dnsBinaryTruncate(msg, maxSize, index, true) indexRRs(msg.Extra, index)
msg.Answer = msg.Answer[:blen] blen := dnsBinaryTruncate(msg, maxSize, index, true)
syncExtra(index, msg) msg.Answer = msg.Answer[:blen]
predicted := msg.Len() syncExtra(index, msg)
buf, err := msg.Pack() predicted := msg.Len()
if err != nil { buf, err := msg.Pack()
t.Error(err) if err != nil {
} t.Error(err)
if predicted < len(buf) { }
t.Fatalf("Bug in DNS library: %d != %d", predicted, len(buf)) if predicted < len(buf) {
} t.Fatalf("Bug in DNS library: %d != %d", predicted, len(buf))
if len(buf) > maxSize || (idx != 0 && len(buf) < 16) || (maxSize == 65535 && blen != 50) { }
t.Fatalf("bad[%d]: %d > %d", idx, len(buf), maxSize) if len(buf) > maxSize || (idx != 0 && len(buf) < 16) || (maxSize == 65535 && blen != 50) {
} t.Fatalf("bad[%d]: %d > %d", idx, len(buf), maxSize)
}
})
} }
} }