mirror of https://github.com/hashicorp/consul
Adds unit tests for prepared queries and DNS, using existing tests for equivalence.
parent
4a0a60af55
commit
81b43135f9
|
@ -9,6 +9,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/consul"
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
@ -555,17 +556,25 @@ func (d *DNSServer) preparedQueryLookup(network, datacenter, query string, req,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the network is not TCP then we just get enough responses to
|
// TODO (slackpad) - What's a safe limit we can set here? It seems like
|
||||||
// tell that things got truncated. This saves bandwidth since we
|
// with dup filtering done at this level we need to get everything to
|
||||||
// will trim the list anyway.
|
// match the previous behavior. We can optimize by pushing more filtering
|
||||||
if network != "tcp" {
|
// into the query execution, but for now I think we need to get the full
|
||||||
args.Limit = maxServiceResponses + 1
|
// response.
|
||||||
}
|
|
||||||
|
|
||||||
endpoint := d.agent.getEndpoint(preparedQueryEndpoint)
|
endpoint := d.agent.getEndpoint(preparedQueryEndpoint)
|
||||||
var out structs.PreparedQueryExecuteResponse
|
var out structs.PreparedQueryExecuteResponse
|
||||||
RPC:
|
RPC:
|
||||||
if err := d.agent.RPC(endpoint+".Execute", &args, &out); err != nil {
|
if err := d.agent.RPC(endpoint+".Execute", &args, &out); err != nil {
|
||||||
|
// If they give a bogus query name, treat that as a name error,
|
||||||
|
// not a full on server error. We have to use a string compare
|
||||||
|
// here since the RPC layer loses the type information.
|
||||||
|
if err.Error() == consul.ErrQueryNotFound.Error() {
|
||||||
|
d.addSOA(d.domain, resp)
|
||||||
|
resp.SetRcode(req, dns.RcodeNameError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
d.logger.Printf("[ERR] dns: rpc error: %v", err)
|
d.logger.Printf("[ERR] dns: rpc error: %v", err)
|
||||||
resp.SetRcode(req, dns.RcodeServerFailure)
|
resp.SetRcode(req, dns.RcodeServerFailure)
|
||||||
return
|
return
|
||||||
|
@ -578,6 +587,11 @@ RPC:
|
||||||
goto RPC
|
goto RPC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO (slackpad) Do we want to apply the DNS server's per-service TTL
|
||||||
|
// configs if the query's TTL is not set? That seems like it adds a lot
|
||||||
|
// of complexity (we'd have to plumb the service name back with the query
|
||||||
|
// results to do this), but is it what people would expect?
|
||||||
|
|
||||||
// Determine the TTL. The parse should never fail since we vet it when
|
// Determine the TTL. The parse should never fail since we vet it when
|
||||||
// the query is created, but we check anyway.
|
// the query is created, but we check anyway.
|
||||||
var ttl time.Duration
|
var ttl time.Duration
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1077,7 +1077,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
|
||||||
|
|
||||||
var reply structs.PreparedQueryExecuteResponse
|
var reply structs.PreparedQueryExecuteResponse
|
||||||
err := msgpackrpc.CallWithCodec(codec1, "PreparedQuery.Execute", &req, &reply)
|
err := msgpackrpc.CallWithCodec(codec1, "PreparedQuery.Execute", &req, &reply)
|
||||||
if err == nil || !strings.Contains(err.Error(), ErrQueryNotFound.Error()) {
|
if err == nil || err.Error() != ErrQueryNotFound.Error() {
|
||||||
t.Fatalf("bad: %v", err)
|
t.Fatalf("bad: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue