From caed0afc8dc365024ae4c37d92dd929c9626f36e Mon Sep 17 00:00:00 2001 From: losalex <90795544+losalex@users.noreply.github.com> Date: Fri, 2 Sep 2022 20:05:44 +0300 Subject: [PATCH] fix: maxRetries parameter is ignored (#1326) * fix: maxRetries parameter is ignored * Fix accessing maxResults * Add tests --- src/log.ts | 9 +++++++++ test/log.ts | 30 ++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/log.ts b/src/log.ts index e48c85aa..caef889b 100644 --- a/src/log.ts +++ b/src/log.ts @@ -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, diff --git a/test/log.ts b/test/log.ts index f8b2a24d..b3e5dcdf 100644 --- a/test/log.ts +++ b/test/log.ts @@ -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(), @@ -114,7 +115,6 @@ describe('Log', () => { if (maxEntrySize) { options.maxEntrySize = maxEntrySize; } - return new Log(LOGGING, LOG_NAME, options); } @@ -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', () => {