Skip to content

Commit

Permalink
fix: maxRetries parameter is ignored (#1326)
Browse files Browse the repository at this point in the history
* fix: maxRetries parameter is ignored

* Fix accessing maxResults

* Add tests
  • Loading branch information
losalex committed Sep 2, 2022
1 parent d622dc3 commit caed0af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,15 @@ class Log implements LogSeverityFunctions {
options
);
delete reqOpts.gaxOptions;
// Propagate maxRetries properly into writeLogEntries call
if (!options.gaxOptions?.maxRetries && this.logging.options?.maxRetries) {
options.gaxOptions = extend(
{
maxRetries: this.logging.options.maxRetries,
},
options.gaxOptions
);
}
return this.logging.loggingService.writeLogEntries(
reqOpts,
options.gaxOptions,
Expand Down
30 changes: 28 additions & 2 deletions test/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ describe('Log', () => {
});

// Create a mock Logging instance
function createLogger(maxEntrySize?: number) {
function createLogger(maxEntrySize?: number, maxRetries?: number) {
LOGGING = {
options: maxRetries !== undefined ? {maxRetries: maxRetries} : undefined,
projectId: '{{project-id}}',
entry: sinon.stub(),
setProjectId: sinon.stub(),
Expand Down Expand Up @@ -114,7 +115,6 @@ describe('Log', () => {
if (maxEntrySize) {
options.maxEntrySize = maxEntrySize;
}

return new Log(LOGGING, LOG_NAME, options);
}

Expand Down Expand Up @@ -578,6 +578,32 @@ describe('Log', () => {
)
);
});

it('should pass through global options', async () => {
log = createLogger(undefined, 1);
decorateEntriesStub = sinon.stub(log, 'decorateEntries').returnsArg(0);
await log.write(ENTRIES, OPTIONS);
assert(
log.logging.loggingService.writeLogEntries.calledWith(
sinon.match.any,
{
maxRetries: 1,
},
sinon.match.any
)
);
log.logging.loggingService.writeLogEntries.reset();
await log.write(ENTRIES, {gaxOptions: {maxRetries: 10}});
assert(
log.logging.loggingService.writeLogEntries.calledWith(
sinon.match.any,
{
maxRetries: 10,
},
sinon.match.any
)
);
});
});

describe('decorateEntries', () => {
Expand Down

0 comments on commit caed0af

Please sign in to comment.