@@ -5,8 +5,10 @@ import (
5
5
"testing"
6
6
7
7
"google.golang.org/api/googleapi"
8
+ "google.golang.org/genproto/googleapis/rpc/errdetails"
8
9
"google.golang.org/grpc/codes"
9
10
"google.golang.org/grpc/status"
11
+ "google.golang.org/protobuf/types/known/durationpb"
10
12
)
11
13
12
14
func TestIsAppEngineRetryableError_operationInProgress (t * testing.T ) {
@@ -114,19 +116,34 @@ func TestIs403QuotaExceededPerMinuteError_perDayQuotaExceededNotRetryable(t *tes
114
116
}
115
117
}
116
118
117
- func TestGRPCRetryable (t * testing.T ) {
118
- code := codes .FailedPrecondition
119
- err := status .Error (code , "is retryable" )
120
- isRetryable , _ := isBigTableRetryableError (err )
119
+ // An error with retry info is retryable.
120
+ func TestBigtableError_retryable (t * testing.T ) {
121
+ retryInfo := & errdetails.RetryInfo {
122
+ RetryDelay : & durationpb.Duration {Seconds : 10 , Nanos : 10 },
123
+ }
124
+ status , _ := status .New (codes .FailedPrecondition , "is retryable" ).WithDetails (retryInfo )
125
+ isRetryable , _ := isBigTableRetryableError (status .Err ())
121
126
if ! isRetryable {
122
127
t .Errorf ("Error not detected as retryable" )
123
128
}
124
129
}
125
130
126
- func TestGRPCNotRetryable (t * testing.T ) {
127
- code := codes .InvalidArgument
128
- err := status .Error (code , "is noto retryable" )
129
- isRetryable , _ := isBigTableRetryableError (err )
131
+ // An error without retry info is not retryable.
132
+ func TestBigtableError_withoutRetryInfoNotRetryable (t * testing.T ) {
133
+ status := status .New (codes .FailedPrecondition , "is not retryable" )
134
+ isRetryable , _ := isBigTableRetryableError (status .Err ())
135
+ if isRetryable {
136
+ t .Errorf ("Error incorrectly detected as retryable" )
137
+ }
138
+ }
139
+
140
+ // An OK status with retry info is not retryable.
141
+ func TestBigtableError_okIsNotRetryable (t * testing.T ) {
142
+ retryInfo := & errdetails.RetryInfo {
143
+ RetryDelay : & durationpb.Duration {Seconds : 10 , Nanos : 10 },
144
+ }
145
+ status , _ := status .New (codes .OK , "is not retryable" ).WithDetails (retryInfo )
146
+ isRetryable , _ := isBigTableRetryableError (status .Err ())
130
147
if isRetryable {
131
148
t .Errorf ("Error incorrectly detected as retryable" )
132
149
}
0 commit comments