Commit 23d60ad9 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 3a3e0375 66eec660
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'));
......
...@@ -169,9 +169,12 @@ export default { ...@@ -169,9 +169,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
...@@ -202,6 +205,7 @@ export default { ...@@ -202,6 +205,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