Commit 5b2ba400 authored by Frédéric Caplette's avatar Frédéric Caplette Committed by Scott Hampton

Fix flaky jest spec in links_layer_spec.js

parent 967a403c
...@@ -2,6 +2,11 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -2,6 +2,11 @@ import axios from '~/lib/utils/axios_utils';
import { reportToSentry } from '../../utils'; import { reportToSentry } from '../../utils';
export const reportPerformance = (path, stats) => { export const reportPerformance = (path, stats) => {
// FIXME: https://gitlab.com/gitlab-org/gitlab/-/issues/330245
if (!path) {
return;
}
axios.post(path, stats).catch((err) => { axios.post(path, stats).catch((err) => {
reportToSentry('links_inner_perf', `error: ${err}`); reportToSentry('links_inner_perf', `error: ${err}`);
}); });
......
...@@ -96,23 +96,19 @@ describe('links layer component', () => { ...@@ -96,23 +96,19 @@ describe('links layer component', () => {
}); });
describe('performance metrics', () => { describe('performance metrics', () => {
const metricsPath = '/root/project/-/ci/prometheus_metrics/histograms.json';
let markAndMeasure; let markAndMeasure;
let reportToSentry; let reportToSentry;
let reportPerformance; let reportPerformance;
let mock; let mock;
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios);
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => cb()); jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => cb());
markAndMeasure = jest.spyOn(perfUtils, 'performanceMarkAndMeasure'); markAndMeasure = jest.spyOn(perfUtils, 'performanceMarkAndMeasure');
reportToSentry = jest.spyOn(sentryUtils, 'reportToSentry'); reportToSentry = jest.spyOn(sentryUtils, 'reportToSentry');
reportPerformance = jest.spyOn(Api, 'reportPerformance'); reportPerformance = jest.spyOn(Api, 'reportPerformance');
}); });
afterEach(() => {
mock.restore();
});
describe('with no metrics config object', () => { describe('with no metrics config object', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
...@@ -164,7 +160,6 @@ describe('links layer component', () => { ...@@ -164,7 +160,6 @@ describe('links layer component', () => {
}); });
describe('with metrics path and collect set to true', () => { describe('with metrics path and collect set to true', () => {
const metricsPath = '/root/project/-/ci/prometheus_metrics/histograms.json';
const duration = 875; const duration = 875;
const numLinks = 7; const numLinks = 7;
const totalGroups = 8; const totalGroups = 8;
...@@ -204,6 +199,9 @@ describe('links layer component', () => { ...@@ -204,6 +199,9 @@ describe('links layer component', () => {
describe('with duration and no error', () => { describe('with duration and no error', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios);
mock.onPost(metricsPath).reply(200, {});
jest.spyOn(window.performance, 'getEntriesByName').mockImplementation(() => { jest.spyOn(window.performance, 'getEntriesByName').mockImplementation(() => {
return [{ duration }]; return [{ duration }];
}); });
...@@ -218,6 +216,10 @@ describe('links layer component', () => { ...@@ -218,6 +216,10 @@ describe('links layer component', () => {
}); });
}); });
afterEach(() => {
mock.restore();
});
it('it calls reportPerformance with expected arguments', () => { it('it calls reportPerformance with expected arguments', () => {
expect(markAndMeasure).toHaveBeenCalled(); expect(markAndMeasure).toHaveBeenCalled();
expect(reportPerformance).toHaveBeenCalled(); expect(reportPerformance).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