GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: raise error on retryable error when max retries is 0 (#1605) · googleapis/google-cloud-node@cdfdda3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • core/packages/gax-nodejs/gax
    • src/streamingCalls
      • streaming.ts
    • test/test-application/src
      • index.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎core/packages/gax-nodejs/gax/src/streamingCalls/streaming.ts‎

Copy file name to clipboardExpand all lines: core/packages/gax-nodejs/gax/src/streamingCalls/streaming.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
438438
return; // end chunk
439439
}
440440
} else {
441+
if (maxRetries === 0) {
442+
const e = GoogleError.parseGRPCStatusDetails(error);
443+
e.note = 'Max retries is set to zero.';
444+
this.destroy(e);
445+
return; // end chunk
446+
}
441447
return GoogleError.parseGRPCStatusDetails(error);
442448
}
443449
});
Collapse file

‎core/packages/gax-nodejs/gax/test/test-application/src/index.ts‎

Copy file name to clipboardExpand all lines: core/packages/gax-nodejs/gax/test/test-application/src/index.ts
+78-3Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
GoogleAuth,
2929
Status,
3030
createBackoffSettings,
31+
createMaxRetriesBackoffSettings,
3132
RetryOptions,
3233
} from 'google-gax';
3334
import {RequestType} from 'google-gax/build/src/apitypes';
@@ -108,6 +109,7 @@ async function testShowcase() {
108109
await testChatThrows(restClientCompat); // REGAPIC does not support bidi streaming
109110
await testWait(restClientCompat);
110111
// Testing with gaxServerStreamingRetries being true
112+
111113
await testServerStreamingRetryOptions(
112114
grpcSequenceClientWithServerStreamingRetries
113115
);
@@ -144,6 +146,12 @@ async function testShowcase() {
144146
grpcSequenceClientWithServerStreamingRetries
145147
);
146148

149+
await testShouldFailOnThirdError(
150+
grpcSequenceClientWithServerStreamingRetries
151+
);
152+
153+
await testErrorMaxRetries0(grpcSequenceClientWithServerStreamingRetries);
154+
// ensure legacy tests pass with streaming retries client
147155
await testEcho(grpcClientWithServerStreamingRetries);
148156
await testEchoError(grpcClientWithServerStreamingRetries);
149157
await testExpand(grpcClientWithServerStreamingRetries);
@@ -152,9 +160,6 @@ async function testShowcase() {
152160
await testCollect(grpcClientWithServerStreamingRetries);
153161
await testChat(grpcClientWithServerStreamingRetries);
154162
await testWait(grpcClientWithServerStreamingRetries);
155-
await testShouldFailOnThirdError(
156-
grpcSequenceClientWithServerStreamingRetries
157-
);
158163
}
159164

160165
function createStreamingSequenceRequestFactory(
@@ -1146,6 +1151,76 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries(
11461151
});
11471152
}
11481153

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+
11491224
async function main() {
11501225
const showcaseServer = new ShowcaseServer();
11511226
try {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.