Skip to content

Commit

Permalink
test: test custom timeout sample (googleapis#8589)
Browse files Browse the repository at this point in the history
Co-authored-by: rahul2393 <[email protected]>
  • Loading branch information
olavloite and rahul2393 authored Sep 28, 2023
1 parent e9ae601 commit 0ab7b1d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions spanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4260,3 +4260,47 @@ func TestClient_CloseWithUnresponsiveBackend(t *testing.T) {
t.Fatalf("context error mismatch\nWant: nil\nGot: %v", ctx.Err())
}
}

func TestClient_CustomRetryAndTimeoutSettings(t *testing.T) {
co := &vkit.CallOptions{
ExecuteSql: []gax.CallOption{
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 500 * time.Millisecond,
Max: 64000 * time.Millisecond,
Multiplier: 1.5,
})
}),
},
}
server, client, teardown := setupMockedTestServerWithConfig(t, ClientConfig{CallOptions: co})
defer teardown()
server.TestSpanner.PutExecutionTime(
MethodExecuteSql,
SimulatedExecutionTime{MinimumExecutionTime: time.Second},
)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
defer cancel()

_, err := client.ReadWriteTransaction(
ctx, func(ctx context.Context, tx *ReadWriteTransaction) error {
c, err := tx.Update(ctx, NewStatement(UpdateBarSetFoo))
if err != nil {
return err
}
if g, w := c, int64(UpdateBarSetFooRowCount); g != w {
return fmt.Errorf("update count mismatch\n Got: %v\nWant: %v", g, w)
}
return nil
})
if err == nil {
t.Fatal("missing expected error")
}
se := ToSpannerError(err)
if g, w := ErrCode(se), codes.DeadlineExceeded; g != w {
t.Fatalf("error code mismatch\n Got: %v\nWant: %v", g, w)
}
}

0 comments on commit 0ab7b1d

Please sign in to comment.