Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(spanner): verify that RESOURCE_EXHAUSTED is retried #11450

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -657,12 +658,29 @@ func TestClient_Single(t *testing.T) {

func TestClient_Single_Unavailable(t *testing.T) {
t.Parallel()
err := testSingleQuery(t, status.Error(codes.Unavailable, "Temporary unavailable"))
err := testSingleQuery(t, serverErrorWithMinimalRetryDelay(codes.Unavailable, "Temporary unavailable"))
if err != nil {
t.Fatal(err)
}
}

func TestClient_Single_ResourceExhausted(t *testing.T) {
t.Parallel()
err := testSingleQuery(t, serverErrorWithMinimalRetryDelay(codes.ResourceExhausted, "Temporary server overload"))
if err != nil {
t.Fatal(err)
}
}

func serverErrorWithMinimalRetryDelay(code codes.Code, msg string) error {
st := status.New(code, msg)
retry := &errdetails.RetryInfo{
RetryDelay: durationpb.New(time.Nanosecond),
}
st, _ = st.WithDetails(retry)
return st.Err()
}

func TestClient_Single_InvalidArgument(t *testing.T) {
t.Parallel()
err := testSingleQuery(t, status.Error(codes.InvalidArgument, "Invalid argument"))
Expand Down Expand Up @@ -1172,8 +1190,18 @@ func checkReqsForTransactionOptions(t *testing.T, server InMemSpannerServer, txo

func testSingleQuery(t *testing.T, serverError error) error {
ctx := context.Background()
server, client, teardown := setupMockedTestServer(t)
server, client, teardown := setupMockedTestServerWithConfig(t, ClientConfig{SessionPoolConfig: SessionPoolConfig{MinOpened: 1}})
defer teardown()
// Wait until all sessions have been created, so we know that those requests will not interfere with the test.
sp := client.idleSessions
waitFor(t, func() error {
sp.mu.Lock()
defer sp.mu.Unlock()
if uint64(sp.idleList.Len()) != sp.MinOpened {
return fmt.Errorf("num open sessions mismatch.\nGot: %d\nWant: %d", sp.numOpened, sp.MinOpened)
}
return nil
})

if serverError != nil {
server.TestSpanner.SetError(serverError)
Expand Down
Loading