agent: Adding test for DNS enable_truncate

This commit is contained in:
Armon Dadgar 2015-05-05 14:14:41 -07:00
parent ea577fbf70
commit 27a820d611
2 changed files with 47 additions and 1 deletions

View File

@ -492,8 +492,9 @@ RPC:
// If the network is not TCP, restrict the number of responses
if network != "tcp" && len(out.Nodes) > maxServiceResponses {
out.Nodes = out.Nodes[:maxServiceResponses]
// Flag that there are more records to return in the UDP response
if d.config.EnableTruncate == true {
if d.config.EnableTruncate {
resp.Truncated = true
}
}

View File

@ -1217,6 +1217,51 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) {
}
}
func TestDNS_ServiceLookup_Truncate(t *testing.T) {
config := &DNSConfig{
EnableTruncate: true,
}
dir, srv := makeDNSServer(t, config, nil)
defer os.RemoveAll(dir)
defer srv.agent.Shutdown()
testutil.WaitForLeader(t, srv.agent.RPC, "dc1")
// Register nodes
for i := 0; i < 3*maxServiceResponses; i++ {
args := &structs.RegisterRequest{
Datacenter: "dc1",
Node: fmt.Sprintf("foo%d", i),
Address: fmt.Sprintf("127.0.0.%d", i+1),
Service: &structs.NodeService{
Service: "web",
Port: 8000,
},
}
var out struct{}
if err := srv.agent.RPC("Catalog.Register", args, &out); err != nil {
t.Fatalf("err: %v", err)
}
}
// Ensure the response is randomized each time.
m := new(dns.Msg)
m.SetQuestion("web.service.consul.", dns.TypeANY)
addr, _ := srv.agent.config.ClientListener("", srv.agent.config.Ports.DNS)
c := new(dns.Client)
in, _, err := c.Exchange(m, addr.String())
if err != nil {
t.Fatalf("err: %v", err)
}
// Check for the truncate bit
if !in.Truncated {
t.Fatalf("should have truncate bit")
}
}
func TestDNS_ServiceLookup_CNAME(t *testing.T) {
recursor := makeRecursor(t, []dns.RR{
dnsCNAME("www.google.com", "google.com"),