@@ -18,6 +18,7 @@ package cdsbalancer
1818
1919import (
2020 "context"
21+ "fmt"
2122 "strings"
2223 "testing"
2324 "time"
@@ -31,6 +32,7 @@ import (
3132 "google.golang.org/grpc/internal/testutils/xds/e2e"
3233 "google.golang.org/grpc/internal/xds/balancer/priority"
3334 "google.golang.org/grpc/internal/xds/xdsclient/xdsresource/version"
35+ "google.golang.org/grpc/resolver"
3436 "google.golang.org/grpc/serviceconfig"
3537 "google.golang.org/grpc/status"
3638
@@ -167,6 +169,7 @@ func (s) TestAggregateClusterSuccess_LeafNode(t *testing.T) {
167169// LogicalDNS and verifies that the load balancing configuration pushed to the
168170// priority LB policy contains the expected config.
169171func (s ) TestAggregateClusterSuccess_ThenUpdateChildClusters (t * testing.T ) {
172+ dnsTargetCh , dnsR := setupDNS (t )
170173 lbCfgCh , _ , _ , _ := registerWrappedPriorityPolicy (t )
171174 mgmtServer , nodeID , _ := setupWithManagementServer (t , nil , nil )
172175
@@ -205,6 +208,20 @@ func (s) TestAggregateClusterSuccess_ThenUpdateChildClusters(t *testing.T) {
205208 t .Fatal (err )
206209 }
207210
211+ // Ensure that the DNS resolver is started for the expected target.
212+ select {
213+ case <- ctx .Done ():
214+ t .Fatal ("Timeout waiting for DNS watch" )
215+ case target := <- dnsTargetCh :
216+ addr := fmt .Sprintf ("%s:%d" , dnsHostName , dnsPort )
217+ if target .Endpoint () != addr {
218+ t .Fatalf ("DNS resolution started for target %q, want %q" , target .Endpoint (), addr )
219+ }
220+ dnsR .UpdateState (resolver.State {
221+ Endpoints : []resolver.Endpoint {{Addresses : []resolver.Address {{Addr : addr }}}},
222+ })
223+ }
224+
208225 wantChildCfg := & priority.LBConfig {
209226 Children : map [string ]* priority.Child {
210227 "priority-0-0" : {
@@ -236,6 +253,18 @@ func (s) TestAggregateClusterSuccess_ThenUpdateChildClusters(t *testing.T) {
236253 if err := mgmtServer .Update (ctx , resources ); err != nil {
237254 t .Fatal (err )
238255 }
256+
257+ select {
258+ case <- ctx .Done ():
259+ t .Fatal ("Timeout waiting for DNS watch" )
260+ case <- dnsTargetCh :
261+ addr1 := fmt .Sprintf ("%s:%d" , dnsHostName , dnsPort )
262+ addr2 := fmt .Sprintf ("%s:%d" , dnsHostNameNew , dnsPort )
263+ dnsR .UpdateState (resolver.State {
264+ Endpoints : []resolver.Endpoint {{Addresses : []resolver.Address {{Addr : addr1 }, {Addr : addr2 }}}},
265+ })
266+ }
267+
239268 wantChildCfg = & priority.LBConfig {
240269 Children : map [string ]* priority.Child {
241270 "priority-0-0" : {
@@ -260,6 +289,7 @@ func (s) TestAggregateClusterSuccess_ThenUpdateChildClusters(t *testing.T) {
260289// configuration pushed to the priority LB policy contains a single discovery
261290// mechanism.
262291func (s ) TestAggregateClusterSuccess_ThenChangeRootToEDS (t * testing.T ) {
292+ dnsTargetCh , dnsR := setupDNS (t )
263293 lbCfgCh , _ , _ , _ := registerWrappedPriorityPolicy (t )
264294 mgmtServer , nodeID , _ := setupWithManagementServer (t , nil , nil )
265295
@@ -282,6 +312,20 @@ func (s) TestAggregateClusterSuccess_ThenChangeRootToEDS(t *testing.T) {
282312 t .Fatal (err )
283313 }
284314
315+ // Ensure that the DNS resolver is started for the expected target.
316+ select {
317+ case <- ctx .Done ():
318+ t .Fatal ("Timeout waiting for DNS watch" )
319+ case target := <- dnsTargetCh :
320+ addr := fmt .Sprintf ("%s:%d" , dnsHostName , dnsPort )
321+ if target .Endpoint () != addr {
322+ t .Fatalf ("DNS resolution started for target %q, want %q" , target .Endpoint (), addr )
323+ }
324+ dnsR .UpdateState (resolver.State {
325+ Endpoints : []resolver.Endpoint {{Addresses : []resolver.Address {{Addr : addr }}}},
326+ })
327+ }
328+
285329 wantChildCfg := & priority.LBConfig {
286330 Children : map [string ]* priority.Child {
287331 "priority-0-0" : {
@@ -330,6 +374,7 @@ func (s) TestAggregateClusterSuccess_ThenChangeRootToEDS(t *testing.T) {
330374// cluster. In each of these cases, the test verifies that the load balancing
331375// configuration pushed to the priority LB policy contains the expected config.
332376func (s ) TestAggregatedClusterSuccess_SwitchBetweenLeafAndAggregate (t * testing.T ) {
377+ dnsTargetCh , dnsR := setupDNS (t )
333378 lbCfgCh , _ , _ , _ := registerWrappedPriorityPolicy (t )
334379 mgmtServer , nodeID , _ := setupWithManagementServer (t , nil , nil )
335380
@@ -375,6 +420,21 @@ func (s) TestAggregatedClusterSuccess_SwitchBetweenLeafAndAggregate(t *testing.T
375420 if err := mgmtServer .Update (ctx , resources ); err != nil {
376421 t .Fatal (err )
377422 }
423+
424+ // Ensure that the DNS resolver is started for the expected target.
425+ select {
426+ case <- ctx .Done ():
427+ t .Fatal ("Timeout waiting for DNS watch" )
428+ case target := <- dnsTargetCh :
429+ addr := fmt .Sprintf ("%s:%d" , dnsHostName , dnsPort )
430+ if target .Endpoint () != addr {
431+ t .Fatalf ("DNS resolution started for target %q, want %q" , target .Endpoint (), addr )
432+ }
433+ dnsR .UpdateState (resolver.State {
434+ Endpoints : []resolver.Endpoint {{Addresses : []resolver.Address {{Addr : addr }}}},
435+ })
436+ }
437+
378438 wantChildCfg = & priority.LBConfig {
379439 Children : map [string ]* priority.Child {
380440 "priority-0-0" : {
0 commit comments