Skip to content

Commit

Permalink
test(spanner): fix retry unit tests with RESOURCE_EXHAUSTED errors (#…
Browse files Browse the repository at this point in the history
…10117)

* test(spanner): fix retry unit tests with RESOURCE_EXHAUSTED errors

* fix comments
  • Loading branch information
rahul2393 authored May 6, 2024
1 parent b9b55e0 commit b91f658
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3989,7 +3989,6 @@ func TestClient_WithoutCustomBatchTimeout(t *testing.T) {
}

func TestClient_CallOptions(t *testing.T) {
t.Skip("https://github.com/googleapis/google-cloud-go/issues/10069")
t.Parallel()
co := &vkit.CallOptions{
CreateSession: []gax.CallOption{
Expand All @@ -4016,7 +4015,7 @@ func TestClient_CallOptions(t *testing.T) {
cs := &gax.CallSettings{}
// This is the default retry setting.
c.CallOptions.CreateSession[1].Resolve(cs)
if got, want := fmt.Sprintf("%v", cs.Retry()), "&{{250000000 32000000000 1.3 0} [14]}"; got != want {
if got, want := fmt.Sprintf("%v", cs.Retry()), "&{{250000000 32000000000 1.3 0} [14 8]}"; got != want {
t.Fatalf("merged CallOptions is incorrect: got %v, want %v", got, want)
}

Expand Down
3 changes: 2 additions & 1 deletion spanner/internal/testutil/inmem_spanner_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,9 @@ func (s *inMemSpannerServer) BatchCreateSessions(ctx context.Context, req *spann
sessionsToCreate := req.SessionCount
s.mu.Lock()
defer s.mu.Unlock()
// return a non-retryable error if the limit is reached
if s.maxSessionsReturnedByServerInTotal > int32(0) && int32(len(s.sessions)) >= s.maxSessionsReturnedByServerInTotal {
return nil, gstatus.Error(codes.ResourceExhausted, "No more sessions available")
return nil, gstatus.Error(codes.OutOfRange, "No more sessions available")
}
if sessionsToCreate > s.maxSessionsReturnedByServerPerBatchRequest {
sessionsToCreate = s.maxSessionsReturnedByServerPerBatchRequest
Expand Down
5 changes: 2 additions & 3 deletions spanner/sessionclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ func TestBatchCreateSessions_ServerReturnsLessThanRequestedSessions(t *testing.T
}

func TestBatchCreateSessions_ServerExhausted(t *testing.T) {
t.Skip("https://github.com/googleapis/google-cloud-go/issues/10070")
t.Parallel()

numChannels := 4
Expand All @@ -443,12 +442,12 @@ func TestBatchCreateSessions_ServerExhausted(t *testing.T) {
consumer := newTestConsumer(numSessions)
client.sc.batchCreateSessions(numSessions, true, consumer)
<-consumer.receivedAll
// Session creation should end with at least one RESOURCE_EXHAUSTED error.
// Session creation should end with at least one non-retryable error.
if len(consumer.errors) == 0 {
t.Fatalf("Error count mismatch\nGot: %d\nWant: > %d", len(consumer.errors), 0)
}
for _, e := range consumer.errors {
if g, w := status.Code(e.err), codes.ResourceExhausted; g != w {
if g, w := status.Code(e.err), codes.OutOfRange; g != w {
t.Fatalf("Error code mismath\nGot: %v\nWant: %v", g, w)
}
}
Expand Down

0 comments on commit b91f658

Please sign in to comment.