Skip to content

Commit 57b69b4

Browse files
authored
xdsclient: modify how the resource watch state is retrieved for testing (#8499)
1 parent ab9fb6d commit 57b69b4

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

xds/internal/clients/xdsclient/authority.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package xdsclient
2020

2121
import (
2222
"context"
23+
"errors"
2324
"fmt"
2425
"sync"
2526
"sync/atomic"
@@ -955,3 +956,17 @@ func serviceStatusToProto(serviceStatus xdsresource.ServiceStatus) v3adminpb.Cli
955956
return v3adminpb.ClientResourceStatus_UNKNOWN
956957
}
957958
}
959+
960+
func (a *authority) resourceWatchStateForTesting(rType ResourceType, resourceName string) (state xdsresource.ResourceWatchState, err error) {
961+
done := make(chan struct{})
962+
a.xdsClientSerializer.ScheduleOr(func(context.Context) {
963+
state, err = a.activeXDSChannel.channel.ads.adsResourceWatchStateForTesting(rType, resourceName)
964+
close(done)
965+
}, func() {
966+
err = errors.New("failed to retrieve resource watch state because the xDS client is closed")
967+
close(done)
968+
})
969+
<-done
970+
971+
return state, err
972+
}

xds/internal/clients/xdsclient/xdsclient.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,11 @@ func (cs *channelState) adsResourceRemoveUnsubscribedCacheEntries(rType Resource
453453
}
454454

455455
func resourceWatchStateForTesting(c *XDSClient, rType ResourceType, resourceName string) (xdsresource.ResourceWatchState, error) {
456-
c.channelsMu.Lock()
457-
defer c.channelsMu.Unlock()
458-
459-
for _, state := range c.xdsActiveChannels {
460-
if st, err := state.channel.ads.adsResourceWatchStateForTesting(rType, resourceName); err == nil {
461-
return st, nil
462-
}
456+
n := xdsresource.ParseName(resourceName)
457+
a := c.getAuthorityForResource(n)
458+
if a == nil {
459+
return xdsresource.ResourceWatchState{}, fmt.Errorf("unable to find authority for resource name %q", resourceName)
463460
}
464-
return xdsresource.ResourceWatchState{}, fmt.Errorf("unable to find watch state for resource type %q and name %q", rType.TypeName, resourceName)
461+
return a.resourceWatchStateForTesting(rType, resourceName)
462+
465463
}

0 commit comments

Comments
 (0)