@@ -28,6 +28,7 @@ import { |
28 | 28 | GoogleAuth, |
29 | 29 | Status, |
30 | 30 | createBackoffSettings, |
| 31 | + createMaxRetriesBackoffSettings, |
31 | 32 | RetryOptions, |
32 | 33 | } from 'google-gax'; |
33 | 34 | import {RequestType} from 'google-gax/build/src/apitypes'; |
@@ -108,6 +109,7 @@ async function testShowcase() { |
108 | 109 | await testChatThrows(restClientCompat); // REGAPIC does not support bidi streaming |
109 | 110 | await testWait(restClientCompat); |
110 | 111 | // Testing with gaxServerStreamingRetries being true |
| 112 | + |
111 | 113 | await testServerStreamingRetryOptions( |
112 | 114 | grpcSequenceClientWithServerStreamingRetries |
113 | 115 | ); |
@@ -144,6 +146,12 @@ async function testShowcase() { |
144 | 146 | grpcSequenceClientWithServerStreamingRetries |
145 | 147 | ); |
146 | 148 |
|
| 149 | + await testShouldFailOnThirdError( |
| 150 | + grpcSequenceClientWithServerStreamingRetries |
| 151 | + ); |
| 152 | + |
| 153 | + await testErrorMaxRetries0(grpcSequenceClientWithServerStreamingRetries); |
| 154 | + // ensure legacy tests pass with streaming retries client |
147 | 155 | await testEcho(grpcClientWithServerStreamingRetries); |
148 | 156 | await testEchoError(grpcClientWithServerStreamingRetries); |
149 | 157 | await testExpand(grpcClientWithServerStreamingRetries); |
@@ -152,9 +160,6 @@ async function testShowcase() { |
152 | 160 | await testCollect(grpcClientWithServerStreamingRetries); |
153 | 161 | await testChat(grpcClientWithServerStreamingRetries); |
154 | 162 | await testWait(grpcClientWithServerStreamingRetries); |
155 | | - await testShouldFailOnThirdError( |
156 | | - grpcSequenceClientWithServerStreamingRetries |
157 | | - ); |
158 | 163 | } |
159 | 164 |
|
160 | 165 | function createStreamingSequenceRequestFactory( |
@@ -1146,6 +1151,76 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries( |
1146 | 1151 | }); |
1147 | 1152 | } |
1148 | 1153 |
|
| 1154 | +// The test should not retry when the max retries are set to 0 |
| 1155 | +// and the emitted error should bubble up to the user when it does not retry. |
| 1156 | +async function testErrorMaxRetries0(client: SequenceServiceClient) { |
| 1157 | + const finalData: string[] = []; |
| 1158 | + const shouldRetryFn = (error: GoogleError) => { |
| 1159 | + return [4].includes(error!.code!); |
| 1160 | + }; |
| 1161 | + const backoffSettings = createMaxRetriesBackoffSettings( |
| 1162 | + 10000, |
| 1163 | + 2.5, |
| 1164 | + 1000, |
| 1165 | + 0, |
| 1166 | + 1.5, |
| 1167 | + 3000, |
| 1168 | + 0 |
| 1169 | + ); |
| 1170 | + const getResumptionRequestFn = (request: RequestType) => { |
| 1171 | + return request; |
| 1172 | + }; |
| 1173 | + |
| 1174 | + const retryOptions = new RetryOptions( |
| 1175 | + [], |
| 1176 | + backoffSettings, |
| 1177 | + shouldRetryFn, |
| 1178 | + getResumptionRequestFn |
| 1179 | + ); |
| 1180 | + |
| 1181 | + const settings = { |
| 1182 | + retry: retryOptions, |
| 1183 | + }; |
| 1184 | + |
| 1185 | + client.initialize(); |
| 1186 | + |
| 1187 | + const request = createStreamingSequenceRequestFactory( |
| 1188 | + [Status.DEADLINE_EXCEEDED, Status.OK], |
| 1189 | + [0.1, 0.1], |
| 1190 | + [0, 1], |
| 1191 | + 'This is testing the brand new and shiny StreamingSequence server 3' |
| 1192 | + ); |
| 1193 | + const response = await client.createStreamingSequence(request); |
| 1194 | + await new Promise<void>((resolve, reject) => { |
| 1195 | + const sequence = response[0]; |
| 1196 | + |
| 1197 | + const attemptRequest = |
| 1198 | + new protos.google.showcase.v1beta1.AttemptStreamingSequenceRequest(); |
| 1199 | + attemptRequest.name = sequence.name!; |
| 1200 | + const attemptStream = client.attemptStreamingSequence( |
| 1201 | + attemptRequest, |
| 1202 | + settings |
| 1203 | + ); |
| 1204 | + attemptStream.on('data', () => { |
| 1205 | + reject(new GoogleError('The stream should not receive any data')); |
| 1206 | + }); |
| 1207 | + attemptStream.on('error', (error: GoogleError) => { |
| 1208 | + try { |
| 1209 | + assert.strictEqual(error.code, 4); |
| 1210 | + assert.strictEqual(error.note, 'Max retries is set to zero.'); |
| 1211 | + resolve(); |
| 1212 | + } catch (assertionError: unknown) { |
| 1213 | + reject(assertionError); |
| 1214 | + } |
| 1215 | + }); |
| 1216 | + attemptStream.on('end', () => { |
| 1217 | + reject( |
| 1218 | + new GoogleError('The stream should not end before it receives an error') |
| 1219 | + ); |
| 1220 | + }); |
| 1221 | + }); |
| 1222 | +} |
| 1223 | + |
1149 | 1224 | async function main() { |
1150 | 1225 | const showcaseServer = new ShowcaseServer(); |
1151 | 1226 | try { |
|