Commit 5c6204f3 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'fix-polling-bug-pipeline-header' into 'master'

Fix polling bug on pipeline header

See merge request gitlab-org/gitlab!47301
parents 42f81b36 156171ca
......@@ -16,6 +16,7 @@ export default {
name: 'PipelineHeaderSection',
pipelineCancel: 'pipelineCancel',
pipelineRetry: 'pipelineRetry',
finishedStatuses: ['FAILED', 'SUCCESS', 'CANCELED'],
components: {
ciHeader,
GlAlert,
......@@ -95,6 +96,9 @@ export default {
status() {
return this.pipeline?.status;
},
isFinished() {
return this.$options.finishedStatuses.includes(this.status);
},
shouldRenderContent() {
return !this.isLoadingInitialQuery && this.hasPipelineData;
},
......@@ -123,6 +127,13 @@ export default {
}
},
},
watch: {
isFinished(finished) {
if (finished) {
this.$apollo.queries.pipeline.stopPolling();
}
},
},
methods: {
reportFailure(errorType) {
this.failureType = errorType;
......@@ -141,7 +152,10 @@ export default {
if (errors.length > 0) {
this.reportFailure(POST_FAILURE);
} else {
this.$apollo.queries.pipeline.refetch();
await this.$apollo.queries.pipeline.refetch();
if (!this.isFinished) {
this.$apollo.queries.pipeline.startPolling(POLL_INTERVAL);
}
}
} catch {
this.reportFailure(POST_FAILURE);
......
......@@ -97,6 +97,24 @@ describe('Pipeline details header', () => {
);
});
describe('polling', () => {
it('is stopped when pipeline is finished', async () => {
wrapper = createComponent({ ...mockRunningPipelineHeader });
await wrapper.setData({
pipeline: { ...mockCancelledPipelineHeader },
});
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).toHaveBeenCalled();
});
it('is not stopped when pipeline is not finished', () => {
wrapper = createComponent();
expect(wrapper.vm.$apollo.queries.pipeline.stopPolling).not.toHaveBeenCalled();
});
});
describe('actions', () => {
describe('Retry action', () => {
beforeEach(() => {
......
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