Skip to content

Commit

Permalink
clusterresolver/e2e_test: Avoid making DNS requests (#7561)
Browse files Browse the repository at this point in the history
* Avoid making a DNS request in aggregated_cluster_test

* Mock DNS resolver
  • Loading branch information
arjan-bal authored Aug 29, 2024
1 parent 52961f7 commit 55d820d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion resolver/manual/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
r.BuildCallback(target, cc, opts)
r.mu.Lock()
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
if r.lastSeenState != nil {
err := r.CC.UpdateState(*r.lastSeenState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ func (s) TestAggregateCluster_BadEDSFromError_GoodToBadDNS(t *testing.T) {
// good update, this test verifies the cluster_resolver balancer correctly falls
// back from the LOGICAL_DNS cluster to the EDS cluster.
func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
dnsTargetCh, dnsR := setupDNS(t)
// Start an xDS management server.
managementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{AllowResourceSubset: true})

Expand All @@ -857,12 +858,14 @@ func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
const (
edsClusterName = clusterName + "-eds"
dnsClusterName = clusterName + "-dns"
dnsHostName = "bad.ip.v4.address"
dnsPort = 8080
)
resources := e2e.UpdateOptions{
NodeID: nodeID,
Clusters: []*v3clusterpb.Cluster{
makeAggregateClusterResource(clusterName, []string{dnsClusterName, edsClusterName}),
makeLogicalDNSClusterResource(dnsClusterName, "bad.ip.v4.address", 8080),
makeLogicalDNSClusterResource(dnsClusterName, dnsHostName, dnsPort),
e2e.DefaultCluster(edsClusterName, edsServiceName, e2e.SecurityLevelNone),
},
Endpoints: []*v3endpointpb.ClusterLoadAssignment{e2e.DefaultEndpoint(edsServiceName, "localhost", []uint32{uint32(edsPort)})},
Expand All @@ -879,6 +882,21 @@ func (s) TestAggregateCluster_BadDNS_GoodEDS(t *testing.T) {
cc, cleanup := setupAndDial(t, bootstrapContents)
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
// EDS cluster.
client := testgrpc.NewTestServiceClient(cc)
Expand Down

0 comments on commit 55d820d

Please sign in to comment.