Commit 67b3a450 authored by Tristan Read's avatar Tristan Read Committed by Kushal Pandya

Ensure that error tracking frontend only polls when required

parent fcda99fa
...@@ -18,7 +18,6 @@ export function startPollingDetails({ commit }, endpoint) { ...@@ -18,7 +18,6 @@ export function startPollingDetails({ commit }, endpoint) {
data: { endpoint }, data: { endpoint },
successCallback: ({ data }) => { successCallback: ({ data }) => {
if (!data) { if (!data) {
detailPoll.restart();
return; return;
} }
...@@ -43,7 +42,6 @@ export function startPollingStacktrace({ commit }, endpoint) { ...@@ -43,7 +42,6 @@ export function startPollingStacktrace({ commit }, endpoint) {
data: { endpoint }, data: { endpoint },
successCallback: ({ data }) => { successCallback: ({ data }) => {
if (!data) { if (!data) {
stackTracePoll.restart();
return; return;
} }
commit(types.SET_STACKTRACE_DATA, data.error); commit(types.SET_STACKTRACE_DATA, data.error);
......
---
title: Ensure that error tracking frontend only polls when required
merge_request: 23305
author:
type: fixed
...@@ -4,27 +4,33 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -4,27 +4,33 @@ import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import * as actions from '~/error_tracking/store/details/actions'; import * as actions from '~/error_tracking/store/details/actions';
import * as types from '~/error_tracking/store/details/mutation_types'; import * as types from '~/error_tracking/store/details/mutation_types';
import Poll from '~/lib/utils/poll';
let mockedAdapter;
let mockedRestart;
jest.mock('~/flash.js'); jest.mock('~/flash.js');
jest.mock('~/lib/utils/url_utility'); jest.mock('~/lib/utils/url_utility');
let mock;
describe('Sentry error details store actions', () => { describe('Sentry error details store actions', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mockedAdapter = new MockAdapter(axios);
}); });
afterEach(() => { afterEach(() => {
mock.restore(); mockedAdapter.restore();
createFlash.mockClear(); createFlash.mockClear();
if (mockedRestart) {
mockedRestart.mockRestore();
mockedRestart = null;
}
}); });
describe('startPollingDetails', () => { describe('startPollingDetails', () => {
const endpoint = '123/details'; const endpoint = '123/details';
it('should commit SET_ERROR with received response', done => { it('should commit SET_ERROR with received response', done => {
const payload = { error: { id: 1 } }; const payload = { error: { id: 1 } };
mock.onGet().reply(200, payload); mockedAdapter.onGet().reply(200, payload);
testAction( testAction(
actions.startPollingDetails, actions.startPollingDetails,
{ endpoint }, { endpoint },
...@@ -41,7 +47,7 @@ describe('Sentry error details store actions', () => { ...@@ -41,7 +47,7 @@ describe('Sentry error details store actions', () => {
}); });
it('should show flash on API error', done => { it('should show flash on API error', done => {
mock.onGet().reply(400); mockedAdapter.onGet().reply(400);
testAction( testAction(
actions.startPollingDetails, actions.startPollingDetails,
...@@ -55,13 +61,23 @@ describe('Sentry error details store actions', () => { ...@@ -55,13 +61,23 @@ describe('Sentry error details store actions', () => {
}, },
); );
}); });
it('should not restart polling when receiving an empty 204 response', done => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
mockedAdapter.onGet().reply(204);
testAction(actions.startPollingDetails, { endpoint }, {}, [], [], () => {
expect(mockedRestart).toHaveBeenCalledTimes(0);
done();
});
});
}); });
describe('startPollingStacktrace', () => { describe('startPollingStacktrace', () => {
const endpoint = '123/stacktrace'; const endpoint = '123/stacktrace';
it('should commit SET_ERROR with received response', done => { it('should commit SET_ERROR with received response', done => {
const payload = { error: [1, 2, 3] }; const payload = { error: [1, 2, 3] };
mock.onGet().reply(200, payload); mockedAdapter.onGet().reply(200, payload);
testAction( testAction(
actions.startPollingStacktrace, actions.startPollingStacktrace,
{ endpoint }, { endpoint },
...@@ -78,7 +94,7 @@ describe('Sentry error details store actions', () => { ...@@ -78,7 +94,7 @@ describe('Sentry error details store actions', () => {
}); });
it('should show flash on API error', done => { it('should show flash on API error', done => {
mock.onGet().reply(400); mockedAdapter.onGet().reply(400);
testAction( testAction(
actions.startPollingStacktrace, actions.startPollingStacktrace,
...@@ -92,5 +108,16 @@ describe('Sentry error details store actions', () => { ...@@ -92,5 +108,16 @@ describe('Sentry error details store actions', () => {
}, },
); );
}); });
it('should not restart polling when receiving an empty 204 response', done => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
mockedAdapter.onGet().reply(204);
testAction(actions.startPollingStacktrace, { endpoint }, {}, [], [], () => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
expect(mockedRestart).toHaveBeenCalledTimes(0);
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