Skip to content

Commit

Permalink
fix: do not throw error if both retryCodes and shouldRetryFn are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Nov 27, 2023
1 parent 4953f8f commit a8488ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 47 deletions.
7 changes: 5 additions & 2 deletions gax/src/createApiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {CallOptions, CallSettings, convertRetryOptions} from './gax';
import {retryable} from './normalCalls/retries';
import {addTimeoutArg} from './normalCalls/timeout';
import {StreamingApiCaller} from './streamingCalls/streamingApiCaller';
import {warn} from './warnings';

/**
* Converts an rpc call into an API call governed by the settings.
Expand Down Expand Up @@ -110,9 +111,11 @@ export function createApiCall(
retry.retryCodes.length > 0 &&
retry.shouldRetryFn
) {
throw new Error(
'Only one of retryCodes or shouldRetryFn may be defined'
warn(
'either_retrycodes_or_shouldretryfn',
'Only one of retryCodes or shouldRetryFn may be defined. Ignoring retryCodes.'
);
retry.retryCodes = [];
}
if (!streaming && retry) {
if (retry.shouldRetryFn) {
Expand Down
4 changes: 2 additions & 2 deletions gax/test/unit/apiCallable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe('createApiCall', () => {
const now = new Date();
const originalDeadline = now.getTime() + 100;
const expectedDeadline = now.getTime() + 200;
assert((resp as any)! > originalDeadline);
assert((resp as any)! <= expectedDeadline);
assert((resp as unknown as number)! > originalDeadline);
assert((resp as unknown as number)! <= expectedDeadline);
done();
});
});
Expand Down
43 changes: 0 additions & 43 deletions gax/test/unit/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,49 +1384,6 @@ describe('handles server streaming retries in gax when gaxStreamingRetries is en
}
);
});
it('errors when both retryCodes and shouldRetryFn are passed', done => {
const spy = sinon.spy((...args: Array<{}>) => {
assert.strictEqual(args.length, 3);
const s = new PassThrough({
objectMode: true,
});
return s;
});

const apiCall = createApiCallStreaming(
spy,
streaming.StreamType.SERVER_STREAMING,
false,
true //gaxStreamingRetries
);

const s = apiCall(
{},
{
retry: gax.createRetryOptions(
[14],
{
initialRetryDelayMillis: 100,
retryDelayMultiplier: 1.2,
maxRetryDelayMillis: 1000,
rpcTimeoutMultiplier: 1.5,
maxRpcTimeoutMillis: 3000,
totalTimeoutMillis: 4500,
},
() => {
return true;
}
),
}
);
s.on('error', error => {
assert.strictEqual(
error.message,
'Only one of retryCodes or shouldRetryFn may be defined'
);
done();
});
});
it('allows custom CallOptions.retry settings with retryCodes and new retry behavior', done => {
sinon
.stub(streaming.StreamProxy.prototype, 'forwardEventsWithRetries')
Expand Down

0 comments on commit a8488ce

Please sign in to comment.