Alerting: increase timeout for silences tests (#41918)

This commit is contained in:
Nathan Rodman 2021-11-19 03:07:28 -08:00 committed by GitHub
parent 12e0a94316
commit 81155e2d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,8 @@ import userEvent from '@testing-library/user-event';
jest.mock('./api/alertmanager'); jest.mock('./api/alertmanager');
const TEST_TIMEOUT = 60000;
const mocks = { const mocks = {
api: { api: {
fetchSilences: typeAsJestMock(fetchSilences), fetchSilences: typeAsJestMock(fetchSilences),
@ -99,53 +101,65 @@ describe('Silences', () => {
setDataSourceSrv(new MockDataSourceSrv(dataSources)); setDataSourceSrv(new MockDataSourceSrv(dataSources));
}); });
it('loads and shows silences', async () => { it(
renderSilences(); 'loads and shows silences',
await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled()); async () => {
await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled()); renderSilences();
await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled());
await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled());
expect(ui.silencesTable.query()).not.toBeNull(); expect(ui.silencesTable.query()).not.toBeNull();
const silences = ui.silenceRow.queryAll(); const silences = ui.silenceRow.queryAll();
expect(silences).toHaveLength(2); expect(silences).toHaveLength(2);
expect(silences[0]).toHaveTextContent('foo=bar'); expect(silences[0]).toHaveTextContent('foo=bar');
expect(silences[1]).toHaveTextContent('foo!=bar'); expect(silences[1]).toHaveTextContent('foo!=bar');
}); },
TEST_TIMEOUT
);
it('shows the correct number of silenced alerts', async () => { it(
mocks.api.fetchAlerts.mockImplementation(() => { 'shows the correct number of silenced alerts',
return Promise.resolve([ async () => {
mockAlertmanagerAlert({ mocks.api.fetchAlerts.mockImplementation(() => {
labels: { foo: 'bar', buzz: 'bazz' }, return Promise.resolve([
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] }, mockAlertmanagerAlert({
}), labels: { foo: 'bar', buzz: 'bazz' },
mockAlertmanagerAlert({ status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
labels: { foo: 'bar', buzz: 'bazz' }, }),
status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] }, mockAlertmanagerAlert({
}), labels: { foo: 'bar', buzz: 'bazz' },
]); status: { state: AlertState.Suppressed, silencedBy: ['12345'], inhibitedBy: [] },
}); }),
]);
});
renderSilences(); renderSilences();
await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled()); await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled());
await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled()); await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled());
const silencedAlertRows = ui.silencedAlertCell.getAll(ui.silencesTable.get()); const silencedAlertRows = ui.silencedAlertCell.getAll(ui.silencesTable.get());
expect(silencedAlertRows).toHaveLength(2); expect(silencedAlertRows).toHaveLength(2);
expect(silencedAlertRows[0]).toHaveTextContent('2'); expect(silencedAlertRows[0]).toHaveTextContent('2');
expect(silencedAlertRows[1]).toHaveTextContent('0'); expect(silencedAlertRows[1]).toHaveTextContent('0');
}); },
TEST_TIMEOUT
);
it('filters silences by matchers', async () => { it(
renderSilences(); 'filters silences by matchers',
await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled()); async () => {
await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled()); renderSilences();
await waitFor(() => expect(mocks.api.fetchSilences).toHaveBeenCalled());
await waitFor(() => expect(mocks.api.fetchAlerts).toHaveBeenCalled());
const queryBar = ui.queryBar.get(); const queryBar = ui.queryBar.get();
userEvent.paste(queryBar, 'foo=bar'); userEvent.paste(queryBar, 'foo=bar');
await waitFor(() => expect(ui.silenceRow.getAll()).toHaveLength(1)); await waitFor(() => expect(ui.silenceRow.getAll()).toHaveLength(1));
}); },
TEST_TIMEOUT
);
}); });
describe('Silence edit', () => { describe('Silence edit', () => {
@ -157,94 +171,102 @@ describe('Silence edit', () => {
setDataSourceSrv(new MockDataSourceSrv(dataSources)); setDataSourceSrv(new MockDataSourceSrv(dataSources));
}); });
it('prefills the matchers field with matchers params', async () => { it(
renderSilences( 'prefills the matchers field with matchers params',
`${baseUrlPath}?matchers=${encodeURIComponent('foo=bar,bar=~ba.+,hello!=world,cluster!~us-central.*')}` async () => {
); renderSilences(
await waitFor(() => expect(ui.editor.durationField.query()).not.toBeNull()); `${baseUrlPath}?matchers=${encodeURIComponent('foo=bar,bar=~ba.+,hello!=world,cluster!~us-central.*')}`
);
await waitFor(() => expect(ui.editor.durationField.query()).not.toBeNull());
const matchers = ui.editor.matchersField.queryAll(); const matchers = ui.editor.matchersField.queryAll();
expect(matchers).toHaveLength(4); expect(matchers).toHaveLength(4);
expect(ui.editor.matcherName.query(matchers[0])).toHaveValue('foo'); expect(ui.editor.matcherName.query(matchers[0])).toHaveValue('foo');
expect(ui.editor.matcherOperator(MatcherOperator.equal).query(matchers[0])).not.toBeNull(); expect(ui.editor.matcherOperator(MatcherOperator.equal).query(matchers[0])).not.toBeNull();
expect(ui.editor.matcherValue.query(matchers[0])).toHaveValue('bar'); expect(ui.editor.matcherValue.query(matchers[0])).toHaveValue('bar');
expect(ui.editor.matcherName.query(matchers[1])).toHaveValue('bar'); expect(ui.editor.matcherName.query(matchers[1])).toHaveValue('bar');
expect(ui.editor.matcherOperator(MatcherOperator.regex).query(matchers[1])).not.toBeNull(); expect(ui.editor.matcherOperator(MatcherOperator.regex).query(matchers[1])).not.toBeNull();
expect(ui.editor.matcherValue.query(matchers[1])).toHaveValue('ba.+'); expect(ui.editor.matcherValue.query(matchers[1])).toHaveValue('ba.+');
expect(ui.editor.matcherName.query(matchers[2])).toHaveValue('hello'); expect(ui.editor.matcherName.query(matchers[2])).toHaveValue('hello');
expect(ui.editor.matcherOperator(MatcherOperator.notEqual).query(matchers[2])).not.toBeNull(); expect(ui.editor.matcherOperator(MatcherOperator.notEqual).query(matchers[2])).not.toBeNull();
expect(ui.editor.matcherValue.query(matchers[2])).toHaveValue('world'); expect(ui.editor.matcherValue.query(matchers[2])).toHaveValue('world');
expect(ui.editor.matcherName.query(matchers[3])).toHaveValue('cluster'); expect(ui.editor.matcherName.query(matchers[3])).toHaveValue('cluster');
expect(ui.editor.matcherOperator(MatcherOperator.notRegex).query(matchers[3])).not.toBeNull(); expect(ui.editor.matcherOperator(MatcherOperator.notRegex).query(matchers[3])).not.toBeNull();
expect(ui.editor.matcherValue.query(matchers[3])).toHaveValue('us-central.*'); expect(ui.editor.matcherValue.query(matchers[3])).toHaveValue('us-central.*');
}); },
TEST_TIMEOUT
);
it('creates a new silence', async () => { it(
renderSilences(baseUrlPath); 'creates a new silence',
await waitFor(() => expect(ui.editor.durationField.query()).not.toBeNull()); async () => {
renderSilences(baseUrlPath);
await waitFor(() => expect(ui.editor.durationField.query()).not.toBeNull());
const start = new Date(); const start = new Date();
const end = new Date(start.getTime() + 24 * 60 * 60 * 1000); const end = new Date(start.getTime() + 24 * 60 * 60 * 1000);
const startDateString = dateTime(start).format('YYYY-MM-DD'); const startDateString = dateTime(start).format('YYYY-MM-DD');
const endDateString = dateTime(end).format('YYYY-MM-DD'); const endDateString = dateTime(end).format('YYYY-MM-DD');
userEvent.clear(ui.editor.durationInput.get()); userEvent.clear(ui.editor.durationInput.get());
userEvent.type(ui.editor.durationInput.get(), '1d'); userEvent.type(ui.editor.durationInput.get(), '1d');
await waitFor(() => expect(ui.editor.durationInput.query()).toHaveValue('1d')); await waitFor(() => expect(ui.editor.durationInput.query()).toHaveValue('1d'));
await waitFor(() => expect(ui.editor.timeRange.get()).toHaveTextContent(startDateString)); await waitFor(() => expect(ui.editor.timeRange.get()).toHaveTextContent(startDateString));
await waitFor(() => expect(ui.editor.timeRange.get()).toHaveTextContent(endDateString)); await waitFor(() => expect(ui.editor.timeRange.get()).toHaveTextContent(endDateString));
userEvent.type(ui.editor.matcherName.get(), 'foo'); userEvent.type(ui.editor.matcherName.get(), 'foo');
userEvent.type(ui.editor.matcherOperatorSelect.get(), '='); userEvent.type(ui.editor.matcherOperatorSelect.get(), '=');
userEvent.tab(); userEvent.tab();
userEvent.type(ui.editor.matcherValue.get(), 'bar'); userEvent.type(ui.editor.matcherValue.get(), 'bar');
// TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed // TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed
userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true }); userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true });
userEvent.type(ui.editor.matcherName.getAll()[1], 'bar'); userEvent.type(ui.editor.matcherName.getAll()[1], 'bar');
userEvent.type(ui.editor.matcherOperatorSelect.getAll()[1], '!='); userEvent.type(ui.editor.matcherOperatorSelect.getAll()[1], '!=');
userEvent.tab(); userEvent.tab();
userEvent.type(ui.editor.matcherValue.getAll()[1], 'buzz'); userEvent.type(ui.editor.matcherValue.getAll()[1], 'buzz');
// TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed // TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed
userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true }); userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true });
userEvent.type(ui.editor.matcherName.getAll()[2], 'region'); userEvent.type(ui.editor.matcherName.getAll()[2], 'region');
userEvent.type(ui.editor.matcherOperatorSelect.getAll()[2], '=~'); userEvent.type(ui.editor.matcherOperatorSelect.getAll()[2], '=~');
userEvent.tab(); userEvent.tab();
userEvent.type(ui.editor.matcherValue.getAll()[2], 'us-west-.*'); userEvent.type(ui.editor.matcherValue.getAll()[2], 'us-west-.*');
// TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed // TODO remove skipPointerEventsCheck once https://github.com/jsdom/jsdom/issues/3232 is fixed
userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true }); userEvent.click(ui.editor.addMatcherButton.get(), undefined, { skipPointerEventsCheck: true });
userEvent.type(ui.editor.matcherName.getAll()[3], 'env'); userEvent.type(ui.editor.matcherName.getAll()[3], 'env');
userEvent.type(ui.editor.matcherOperatorSelect.getAll()[3], '!~'); userEvent.type(ui.editor.matcherOperatorSelect.getAll()[3], '!~');
userEvent.tab(); userEvent.tab();
userEvent.type(ui.editor.matcherValue.getAll()[3], 'dev|staging'); userEvent.type(ui.editor.matcherValue.getAll()[3], 'dev|staging');
userEvent.type(ui.editor.comment.get(), 'Test'); userEvent.type(ui.editor.comment.get(), 'Test');
userEvent.type(ui.editor.createdBy.get(), 'Homer Simpson'); userEvent.type(ui.editor.createdBy.get(), 'Homer Simpson');
userEvent.click(ui.editor.submit.get()); userEvent.click(ui.editor.submit.get());
await waitFor(() => await waitFor(() =>
expect(mocks.api.createOrUpdateSilence).toHaveBeenCalledWith( expect(mocks.api.createOrUpdateSilence).toHaveBeenCalledWith(
'grafana', 'grafana',
expect.objectContaining({ expect.objectContaining({
comment: 'Test', comment: 'Test',
createdBy: 'Homer Simpson', createdBy: 'Homer Simpson',
matchers: [ matchers: [
{ isEqual: true, isRegex: false, name: 'foo', value: 'bar' }, { isEqual: true, isRegex: false, name: 'foo', value: 'bar' },
{ isEqual: false, isRegex: false, name: 'bar', value: 'buzz' }, { isEqual: false, isRegex: false, name: 'bar', value: 'buzz' },
{ isEqual: true, isRegex: true, name: 'region', value: 'us-west-.*' }, { isEqual: true, isRegex: true, name: 'region', value: 'us-west-.*' },
{ isEqual: false, isRegex: true, name: 'env', value: 'dev|staging' }, { isEqual: false, isRegex: true, name: 'env', value: 'dev|staging' },
], ],
}) })
) )
); );
}); },
TEST_TIMEOUT
);
}); });