From 7fe9e9c0627b7a99db73cd47f7399a4b1339a0d2 Mon Sep 17 00:00:00 2001 From: Elastic Jasper Date: Mon, 28 Mar 2016 13:27:36 -0400 Subject: [PATCH] Backport PR #6651 --------- **Commit 1:** [courier/segmentedRequest] mark the request "started" synchronously * Original sha: 8a4992640bf1e8f74316dbbad0d5875182b91bbf * Authored by spalger on 2016-03-24T21:35:00Z **Commit 2:** [courier/fetch] detect aborted requests more agressively * Original sha: c12f18df2733f36819d482ad1c8b7152a5450584 * Authored by spalger on 2016-03-24T21:35:46Z **Commit 3:** [courier/callClient] if there are no executable requests, do nothing * Original sha: 8fef03b816e016a1637a2557c1a1cb6e0cab7bc2 * Authored by spalger on 2016-03-24T21:36:18Z **Commit 4:** [courier/tests] updated test * Original sha: 985f9970f3b73863b20d55369ac0e902e27384fd * Authored by spalger on 2016-03-24T22:25:31Z --- src/ui/public/courier/fetch/_call_client.js | 2 ++ src/ui/public/courier/fetch/_fetch_these.js | 12 ++++++++---- .../courier/fetch/request/__tests__/segmented.js | 4 +--- src/ui/public/courier/fetch/request/segmented.js | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ui/public/courier/fetch/_call_client.js b/src/ui/public/courier/fetch/_call_client.js index 1cec794512c33..8cab455a0cb5c 100644 --- a/src/ui/public/courier/fetch/_call_client.js +++ b/src/ui/public/courier/fetch/_call_client.js @@ -16,6 +16,8 @@ define(function (require) { var executable = statuses.filter(isRequest); var execCount = executable.length; + if (!execCount) return Promise.resolve([]); + // resolved by respond() var esPromise; var defer = Promise.defer(); diff --git a/src/ui/public/courier/fetch/_fetch_these.js b/src/ui/public/courier/fetch/_fetch_these.js index a629c9920187f..7b96dadae4689 100644 --- a/src/ui/public/courier/fetch/_fetch_these.js +++ b/src/ui/public/courier/fetch/_fetch_these.js @@ -23,22 +23,26 @@ define(function (require) { } function fetchWithStrategy(strategy, requests) { + function replaceAbortedRequests() { + requests = requests.map(r => r.aborted ? ABORTED : r); + } - requests = requests.map(function (req) { - return req.aborted ? ABORTED : req; - }); - + replaceAbortedRequests(); return startRequests(requests) .then(function () { + replaceAbortedRequests(); return callClient(strategy, requests); }) .then(function (responses) { + replaceAbortedRequests(); return callResponseHandlers(requests, responses); }) .then(function (responses) { + replaceAbortedRequests(); return continueIncomplete(strategy, requests, responses, fetchWithStrategy); }) .then(function (responses) { + replaceAbortedRequests(); return responses.map(function (resp) { switch (resp) { case ABORTED: diff --git a/src/ui/public/courier/fetch/request/__tests__/segmented.js b/src/ui/public/courier/fetch/request/__tests__/segmented.js index 7edfdd69190a1..a3882bc82fbbb 100644 --- a/src/ui/public/courier/fetch/request/__tests__/segmented.js +++ b/src/ui/public/courier/fetch/request/__tests__/segmented.js @@ -29,9 +29,7 @@ describe('ui/courier/fetch/request/segmented', () => { expect(returned.then).to.be.Function; }); - it('does not call super.start() until promise is resolved', () => { - expect(searchReqStart.called).to.be(false); - $rootScope.$apply(); + it('calls super.start() synchronously', () => { expect(searchReqStart.called).to.be(true); }); }); diff --git a/src/ui/public/courier/fetch/request/segmented.js b/src/ui/public/courier/fetch/request/segmented.js index 13ace5fcc0238..f7741b0ba584a 100644 --- a/src/ui/public/courier/fetch/request/segmented.js +++ b/src/ui/public/courier/fetch/request/segmented.js @@ -39,6 +39,8 @@ define(function (require) { SegmentedReq.prototype.start = function () { var self = this; + SearchReq.prototype.start.call(this); + this._complete = []; this._active = null; this._segments = []; @@ -58,12 +60,12 @@ define(function (require) { // parameters via the handle if (_.isFunction(this._initFn)) this._initFn(this._handle); return this._createQueue().then(function (queue) { + if (self.stopped) return; + self._all = queue.slice(0); // Send the initial fetch status self._reportStatus(); - - return SearchReq.prototype.start.call(self); }); };