From 77bcb11285743af9ed3f061a73d5bcea0ce5333e Mon Sep 17 00:00:00 2001 From: Charlene Tshitoka Date: Sat, 27 Jun 2020 23:18:40 -0400 Subject: [PATCH] fix: ensure node retries happen when using .then syntax (#1487) (#1543) --- src/request-base.js | 4 ++++ test/retry.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/request-base.js b/src/request-base.js index d4addf11f..ff519477a 100644 --- a/src/request-base.js +++ b/src/request-base.js @@ -247,6 +247,10 @@ RequestBase.prototype.then = function(resolve, reject) { this._fullfilledPromise = new Promise((resolve, reject) => { self.on('abort', () => { + if (this._maxRetries && this._maxRetries > this._retries) { + return; + } + if (this.timedout && this.timedoutError) { reject(this.timedoutError); return; diff --git a/test/retry.js b/test/retry.js index f8e9e752e..041ef21da 100644 --- a/test/retry.js +++ b/test/retry.js @@ -178,6 +178,26 @@ describe('.retry(count)', function() { }); }); + it('should handle successful request after repeat attempt from server timeout when using .then(fulfill, reject)', done => { + const url = `/delay/1200/ok/${uniqid()}?built=in`; + request + .get(base + url) + .query('string=ified') + .query({ json: 'ed' }) + .timeout(600) + .retry(1) + .then((res, err) => { + try { + assert.ifError(err); + assert(res.ok, 'response should be ok'); + assert.equal(res.text, `ok = ${url}&string=ified&json=ed`); + done(); + } catch (err_) { + done(err_); + } + }); + }); + it('should correctly abort a retry attempt', done => { let aborted = false; const req = request