Skip to content

Commit 5028ef7

Browse files
xdsclient: fix TestConcurrentReportLoad to not run for 10s (#8598)
While working on the fix for the xDS client unsubscribe/resubscribe race, I noticed that the tests in the `internal/xds/xdsclient/tests/` directory were taking about a minute to run. Upon inspection I found that `TestConcurrentReportLoad` was running for the configured test timeout duration of `10s`, but was not failing. This PR fixes the test to run in a short duration. It also makes a couple of other cleanups that I noticed when fixing this test. RELEASE NOTES: none --------- Co-authored-by: eshitachandwani <[email protected]>
1 parent 3722890 commit 5028ef7

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

internal/xds/clients/grpctransport/grpc_transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (b *Builder) Build(si clients.ServerIdentifier) (clients.Transport, error)
111111

112112
if cc, ok := b.connections[si]; ok {
113113
if logger.V(2) {
114-
logger.Info("Reusing existing connection to the server for ServerIdentifier: %v", si)
114+
logger.Infof("Reusing existing connection to the server for ServerIdentifier: %v", si)
115115
}
116116
b.refs[si]++
117117
tr := &grpcTransport{cc: cc}
@@ -148,7 +148,7 @@ func (b *Builder) Build(si clients.ServerIdentifier) (clients.Transport, error)
148148
b.refs[si] = 1
149149

150150
if logger.V(2) {
151-
logger.Info("Created a new transport to the server for ServerIdentifier: %v", si)
151+
logger.Infof("Created a new transport to the server for ServerIdentifier: %v", si)
152152
}
153153
return tr, nil
154154
}

internal/xds/clients/lrsclient/lrsclient.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"sync"
2929
"time"
3030

31-
"google.golang.org/grpc/grpclog"
3231
igrpclog "google.golang.org/grpc/internal/grpclog"
3332
"google.golang.org/grpc/internal/xds/clients"
3433
clientsinternal "google.golang.org/grpc/internal/xds/clients/internal"
@@ -114,10 +113,6 @@ func (c *LRSClient) getOrCreateLRSStream(serverIdentifier clients.ServerIdentifi
114113
c.logger.Infof("Creating a new lrs stream for server identifier %q", serverIdentifier)
115114
}
116115

117-
l := grpclog.Component("xds")
118-
logPrefix := clientPrefix(c)
119-
c.logger = igrpclog.NewPrefixLogger(l, logPrefix)
120-
121116
// Create a new transport and create a new lrs stream, and add it to the
122117
// map of lrs streams.
123118
tr, err := c.transportBuilder.Build(serverIdentifier)
@@ -131,7 +126,7 @@ func (c *LRSClient) getOrCreateLRSStream(serverIdentifier clients.ServerIdentifi
131126
transport: tr,
132127
backoff: c.backoff,
133128
nodeProto: nodeProto,
134-
logPrefix: logPrefix,
129+
logPrefix: clientPrefix(c),
135130
})
136131

137132
// Register a stop function that decrements the reference count, stops

internal/xds/xdsclient/tests/loadreport_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,10 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
448448

449449
// TestConcurrentReportLoad verifies that the client can safely handle concurrent
450450
// requests to initiate load reporting streams. It launches multiple goroutines
451-
// that all call client.ReportLoad simultaneously.
451+
// that all call client.ReportLoad simultaneously. We don't verify anything on
452+
// the server here, since that is done in other tests. This is just to ensure
453+
// that concurrent ReportLoad() calls work.
452454
func (s) TestConcurrentReportLoad(t *testing.T) {
453-
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
454-
defer cancel()
455-
456455
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{SupportLoadReportingService: true})
457456
nodeID := uuid.New().String()
458457
bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)
@@ -464,17 +463,29 @@ func (s) TestConcurrentReportLoad(t *testing.T) {
464463
}
465464

466465
// Call ReportLoad() concurrently from multiple go routines.
467-
var wg sync.WaitGroup
468466
const numGoroutines = 10
467+
cancelStores := make([]func(context.Context), numGoroutines)
468+
var wg sync.WaitGroup
469469
wg.Add(numGoroutines)
470-
for range numGoroutines {
471-
go func() {
470+
for i := range numGoroutines {
471+
go func(idx int) {
472472
defer wg.Done()
473-
_, cancelStore := client.ReportLoad(serverConfig)
474-
defer cancelStore(ctx)
475-
}()
473+
_, cancelStores[idx] = client.ReportLoad(serverConfig)
474+
}(i)
476475
}
477476
wg.Wait()
477+
478+
// Cancel all the load reporting streams. The last call to cancel is
479+
// expected to block until a final load report with pending loads is sent.
480+
// But the stream is currently blocked on a recv() call waiting for the LRS
481+
// server to send the initial laod reporting response, which it never does.
482+
// Hence we use a context with short timeout here.
483+
for i, cancel := range cancelStores {
484+
sCtx, sCancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
485+
defer sCancel()
486+
cancel(sCtx)
487+
t.Logf("Cancelled LRS stream %d", i)
488+
}
478489
}
479490

480491
// TestConcurrentChannels verifies that we can create multiple gRPC channels

0 commit comments

Comments
 (0)