mirror of https://github.com/grpc/grpc-go.git
clusterresolver/e2e_test: Avoid making DNS requests (#7561)
* Avoid making a DNS request in aggregated_cluster_test * Mock DNS resolver
This commit is contained in:
parent
52961f77b0
commit
55d820d900
|
@ -76,9 +76,11 @@ func (r *Resolver) InitialState(s resolver.State) {
|
||||||
|
|
||||||
// Build returns itself for Resolver, because it's both a builder and a resolver.
|
// Build returns itself for Resolver, because it's both a builder and a resolver.
|
||||||
func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
|
func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
|
||||||
r.BuildCallback(target, cc, opts)
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
// Call BuildCallback after locking to avoid a race when UpdateState
|
||||||
|
// or ReportError is called before Build returns.
|
||||||
|
r.BuildCallback(target, cc, opts)
|
||||||
r.CC = cc
|
r.CC = cc
|
||||||
if r.lastSeenState != nil {
|
if r.lastSeenState != nil {
|
||||||
err := r.CC.UpdateState(*r.lastSeenState)
|
err := r.CC.UpdateState(*r.lastSeenState)
|
||||||
|
|
|
@ -840,6 +840,7 @@ func (s) TestAggregateCluster_BadEDSFromError_GoodToBadDNS(t *testing.T) {
|
||||||
// good update, this test verifies the cluster_resolver balancer correctly falls
|
// good update, this test verifies the cluster_resolver balancer correctly falls
|
||||||
// back from the LOGICAL_DNS cluster to the EDS cluster.
|
// back from the LOGICAL_DNS cluster to the EDS cluster.
|
||||||
func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
|
func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
|
||||||
|
dnsTargetCh, dnsR := setupDNS(t)
|
||||||
// Start an xDS management server.
|
// Start an xDS management server.
|
||||||
managementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{AllowResourceSubset: true})
|
managementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{AllowResourceSubset: true})
|
||||||
|
|
||||||
|
@ -857,12 +858,14 @@ func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
edsClusterName = clusterName + "-eds"
|
edsClusterName = clusterName + "-eds"
|
||||||
dnsClusterName = clusterName + "-dns"
|
dnsClusterName = clusterName + "-dns"
|
||||||
|
dnsHostName = "bad.ip.v4.address"
|
||||||
|
dnsPort = 8080
|
||||||
)
|
)
|
||||||
resources := e2e.UpdateOptions{
|
resources := e2e.UpdateOptions{
|
||||||
NodeID: nodeID,
|
NodeID: nodeID,
|
||||||
Clusters: []*v3clusterpb.Cluster{
|
Clusters: []*v3clusterpb.Cluster{
|
||||||
makeAggregateClusterResource(clusterName, []string{dnsClusterName, edsClusterName}),
|
makeAggregateClusterResource(clusterName, []string{dnsClusterName, edsClusterName}),
|
||||||
makeLogicalDNSClusterResource(dnsClusterName, "bad.ip.v4.address", 8080),
|
makeLogicalDNSClusterResource(dnsClusterName, dnsHostName, dnsPort),
|
||||||
e2e.DefaultCluster(edsClusterName, edsServiceName, e2e.SecurityLevelNone),
|
e2e.DefaultCluster(edsClusterName, edsServiceName, e2e.SecurityLevelNone),
|
||||||
},
|
},
|
||||||
Endpoints: []*v3endpointpb.ClusterLoadAssignment{e2e.DefaultEndpoint(edsServiceName, "localhost", []uint32{uint32(edsPort)})},
|
Endpoints: []*v3endpointpb.ClusterLoadAssignment{e2e.DefaultEndpoint(edsServiceName, "localhost", []uint32{uint32(edsPort)})},
|
||||||
|
@ -879,6 +882,21 @@ func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
|
||||||
cc, cleanup := setupAndDial(t, bootstrapContents)
|
cc, cleanup := setupAndDial(t, bootstrapContents)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
|
// Ensure that the DNS resolver is started for the expected target.
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
t.Fatal("Timeout when waiting for DNS resolver to be started")
|
||||||
|
case target := <-dnsTargetCh:
|
||||||
|
got, want := target.Endpoint(), fmt.Sprintf("%s:%d", dnsHostName, dnsPort)
|
||||||
|
if got != want {
|
||||||
|
t.Fatalf("DNS resolution started for target %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Produce a bad resolver update from the DNS resolver.
|
||||||
|
dnsErr := fmt.Errorf("DNS error")
|
||||||
|
dnsR.ReportError(dnsErr)
|
||||||
|
|
||||||
// RPCs should work, higher level DNS cluster errors so should fallback to
|
// RPCs should work, higher level DNS cluster errors so should fallback to
|
||||||
// EDS cluster.
|
// EDS cluster.
|
||||||
client := testgrpc.NewTestServiceClient(cc)
|
client := testgrpc.NewTestServiceClient(cc)
|
||||||
|
|
Loading…
Reference in New Issue