Skip to content

Commit

Permalink
fix race
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindbr8 committed Feb 17, 2023
1 parent ccd48ad commit 26eb7da
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions xds/internal/xdsclient/authority_test.go
Expand Up @@ -126,12 +126,14 @@ func (s) TestResourceDeletionIsIgnored(t *testing.T) {

// Waiting for updates to reach the client.
<-watcherChA
a.resourcesMu.Lock()
if a.resources[rType][resourceNameA].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
if a.resources[rType][resourceNameB].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
a.resourcesMu.Unlock()

// Sending an update without resource B.
resources = e2e.UpdateOptions{
Expand All @@ -146,12 +148,14 @@ func (s) TestResourceDeletionIsIgnored(t *testing.T) {
// Waiting for updates to reach the client.
<-watcherChA
// Verifying that both resources are still in cache.
a.resourcesMu.Lock()
if a.resources[rType][resourceNameA].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
if a.resources[rType][resourceNameB].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
a.resourcesMu.Unlock()

}

Expand Down Expand Up @@ -215,16 +219,18 @@ func (s) TestResourceDeletionIsNotIgnored(t *testing.T) {
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
}

// Wait for updates to reach the client.
// Waiting for updates to reach the client.
<-watcherChA
a.resourcesMu.Lock()
if a.resources[rType][resourceNameA].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
if a.resources[rType][resourceNameB].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
a.resourcesMu.Unlock()

// sending an update without resource B.
// Sending an update without resource B.
resources = e2e.UpdateOptions{
NodeID: nodeID,
Listeners: []*v3listenerpb.Listener{e2e.DefaultClientListener(resourceNameA, "new-rds-resourceAA")},
Expand All @@ -234,14 +240,17 @@ func (s) TestResourceDeletionIsNotIgnored(t *testing.T) {
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
}

// Wait for updates to reach the client.
// Waiting for updates to reach the client.
<-watcherChA
// Verify that both resources are still in cache. And also check that WatcherB was never called
// Verifying that resource A's cache is still valid, while resource B has been
// deleted.
a.resourcesMu.Lock()
if a.resources[rType][resourceNameA].cache == nil {
t.Fatal("Got state = nil, Want valid state for the resource.")
}
if a.resources[rType][resourceNameB].cache != nil {
t.Fatal("Got a valid state for resource, Want resource state cache to be deleted.")
}
a.resourcesMu.Unlock()

}

0 comments on commit 26eb7da

Please sign in to comment.