Commit 27619f26 authored by Phil Hughes's avatar Phil Hughes

Merge branch '56970-fix-mr-stuck-loading-on-error' into 'master'

Resolve "Merge request page loses state"

See merge request gitlab-org/gitlab-ce!25988
parents 893c63da d50fe9e4
export default (fn, interval = 2000, timeout = 60000) => { export default (fn, { interval = 2000, timeout = 60000 } = {}) => {
const startTime = Date.now(); const startTime = Date.now();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const stop = arg => (arg instanceof Error ? reject(arg) : resolve(arg)); const stop = arg => (arg instanceof Error ? reject(arg) : resolve(arg));
const next = () => { const next = () => {
if (Date.now() - startTime < timeout) { if (timeout === 0 || Date.now() - startTime < timeout) {
setTimeout(fn.bind(null, next, stop), interval); setTimeout(fn.bind(null, next, stop), interval);
} else { } else {
reject(new Error('SIMPLE_POLL_TIMEOUT')); reject(new Error('SIMPLE_POLL_TIMEOUT'));
......
...@@ -165,9 +165,12 @@ export default { ...@@ -165,9 +165,12 @@ export default {
}); });
}, },
initiateMergePolling() { initiateMergePolling() {
simplePoll((continuePolling, stopPolling) => { simplePoll(
this.handleMergePolling(continuePolling, stopPolling); (continuePolling, stopPolling) => {
}); this.handleMergePolling(continuePolling, stopPolling);
},
{ timeout: 0 },
);
}, },
handleMergePolling(continuePolling, stopPolling) { handleMergePolling(continuePolling, stopPolling) {
this.service this.service
...@@ -198,6 +201,7 @@ export default { ...@@ -198,6 +201,7 @@ export default {
}) })
.catch(() => { .catch(() => {
new Flash(__('Something went wrong while merging this merge request. Please try again.')); // eslint-disable-line new Flash(__('Something went wrong while merging this merge request. Please try again.')); // eslint-disable-line
stopPolling();
}); });
}, },
initiateRemoveSourceBranchPolling() { initiateRemoveSourceBranchPolling() {
......
---
title: Disable timeout on merge request merging poll
merge_request: 25988
author:
type: fixed
...@@ -377,11 +377,29 @@ describe('ReadyToMerge', () => { ...@@ -377,11 +377,29 @@ describe('ReadyToMerge', () => {
}); });
describe('initiateMergePolling', () => { describe('initiateMergePolling', () => {
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('should call simplePoll', () => { it('should call simplePoll', () => {
const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll'); const simplePoll = spyOnDependency(ReadyToMerge, 'simplePoll');
vm.initiateMergePolling(); vm.initiateMergePolling();
expect(simplePoll).toHaveBeenCalled(); expect(simplePoll).toHaveBeenCalledWith(jasmine.any(Function), { timeout: 0 });
});
it('should call handleMergePolling', () => {
spyOn(vm, 'handleMergePolling');
vm.initiateMergePolling();
jasmine.clock().tick(2000);
expect(vm.handleMergePolling).toHaveBeenCalled();
}); });
}); });
......
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