MCPcopy
hub / github.com/nextdns/nextdns / TestDNSEndpointExchange_MatchesResponseID

Function TestDNSEndpointExchange_MatchesResponseID

resolver/endpoint/dns_test.go:10–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestDNSEndpointExchange_MatchesResponseID(t *testing.T) {
11 ln, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
12 if err != nil {
13 t.Fatalf("ListenUDP: %v", err)
14 }
15 defer ln.Close()
16
17 done := make(chan struct{})
18 go func() {
19 defer close(done)
20 buf := make([]byte, 2048)
21 n, raddr, err := ln.ReadFromUDP(buf)
22 if err != nil || n < 2 {
23 return
24 }
25 // Echo a minimal response with the same ID.
26 resp := make([]byte, 12)
27 resp[0], resp[1] = buf[0], buf[1]
28 _, _ = ln.WriteToUDP(resp, raddr)
29 }()
30
31 e := &DNSEndpoint{Addr: ln.LocalAddr().String()}
32 payload := make([]byte, 12)
33 buf := make([]byte, 514)
34 buf[1] = 0xFF // would have broken the old buggy ID calculation.
35
36 ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
37 defer cancel()
38
39 n, err := e.Exchange(ctx, payload, buf)
40 if err != nil {
41 t.Fatalf("Exchange error: %v", err)
42 }
43 if n < 2 {
44 t.Fatalf("expected n>=2, got %d", n)
45 }
46
47 <-done
48}
49

Callers

nothing calls this directly

Calls 4

ExchangeMethod · 0.95
LocalAddrMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…