Commit 355bf7d5 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 80646fd8 4f5bb088
...@@ -63,6 +63,10 @@ export default class Poll { ...@@ -63,6 +63,10 @@ export default class Poll {
const headers = normalizeHeaders(response.headers); const headers = normalizeHeaders(response.headers);
const pollInterval = parseInt(headers[this.intervalHeader], 10); const pollInterval = parseInt(headers[this.intervalHeader], 10);
if (pollInterval > 0 && successCodes.indexOf(response.status) !== -1 && this.canPoll) { if (pollInterval > 0 && successCodes.indexOf(response.status) !== -1 && this.canPoll) {
if (this.timeoutID) {
clearTimeout(this.timeoutID);
}
this.timeoutID = setTimeout(() => { this.timeoutID = setTimeout(() => {
this.makeRequest(); this.makeRequest();
}, pollInterval); }, pollInterval);
...@@ -101,15 +105,25 @@ export default class Poll { ...@@ -101,15 +105,25 @@ export default class Poll {
} }
/** /**
* Restarts polling after it has been stoped * Enables polling after it has been stopped
*/ */
restart(options) { enable(options) {
// update data
if (options && options.data) { if (options && options.data) {
this.options.data = options.data; this.options.data = options.data;
} }
this.canPoll = true; this.canPoll = true;
if (options && options.response) {
this.checkConditions(options.response);
}
}
/**
* Restarts polling after it has been stopped and makes a request
*/
restart(options) {
this.enable(options);
this.makeRequest(); this.makeRequest();
} }
} }
...@@ -94,8 +94,7 @@ export default { ...@@ -94,8 +94,7 @@ export default {
this.isLoading = false; this.isLoading = false;
this.successCallback(response); this.successCallback(response);
// restart polling this.poll.enable({ data: this.requestData, response });
this.poll.restart({ data: this.requestData });
}) })
.catch(() => { .catch(() => {
this.isLoading = false; this.isLoading = false;
......
---
title: Remove duplicate XHR request when requesting new pipeline page
merge_request: 25506
author:
type: fixed
...@@ -153,6 +153,36 @@ describe('Poll', () => { ...@@ -153,6 +153,36 @@ describe('Poll', () => {
}); });
}); });
describe('enable', () => {
it('should enable polling upon a response', done => {
jasmine.clock().install();
const Polling = new Poll({
resource: service,
method: 'fetch',
data: { page: 1 },
successCallback: () => {},
});
Polling.enable({
data: { page: 4 },
response: { status: 200, headers: { 'poll-interval': 1 } },
});
jasmine.clock().tick(1);
jasmine.clock().uninstall();
waitForAllCallsToFinish(service, 1, () => {
Polling.stop();
expect(service.fetch.calls.count()).toEqual(1);
expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
expect(Polling.options.data).toEqual({ page: 4 });
done();
});
});
});
describe('restart', () => { describe('restart', () => {
it('should restart polling when its called', done => { it('should restart polling when its called', done => {
mockServiceCall(service, { status: 200, headers: { 'poll-interval': 1 } }); mockServiceCall(service, { status: 200, headers: { 'poll-interval': 1 } });
...@@ -171,6 +201,7 @@ describe('Poll', () => { ...@@ -171,6 +201,7 @@ describe('Poll', () => {
}); });
spyOn(Polling, 'stop').and.callThrough(); spyOn(Polling, 'stop').and.callThrough();
spyOn(Polling, 'enable').and.callThrough();
spyOn(Polling, 'restart').and.callThrough(); spyOn(Polling, 'restart').and.callThrough();
Polling.makeRequest(); Polling.makeRequest();
...@@ -181,6 +212,7 @@ describe('Poll', () => { ...@@ -181,6 +212,7 @@ describe('Poll', () => {
expect(service.fetch.calls.count()).toEqual(2); expect(service.fetch.calls.count()).toEqual(2);
expect(service.fetch).toHaveBeenCalledWith({ page: 4 }); expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
expect(Polling.stop).toHaveBeenCalled(); expect(Polling.stop).toHaveBeenCalled();
expect(Polling.enable).toHaveBeenCalled();
expect(Polling.restart).toHaveBeenCalled(); expect(Polling.restart).toHaveBeenCalled();
expect(Polling.options.data).toEqual({ page: 4 }); expect(Polling.options.data).toEqual({ page: 4 });
done(); done();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment