Skip to content

Commit

Permalink
[Synthetics] De-dupe overview status request on load (#161627)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Jul 11, 2023
1 parent 787491e commit 70ed200
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ journey('OverviewScrolling', async ({ page, params }) => {
const syntheticsApp = syntheticsAppPageProvider({ page, kibanaUrl: params.kibanaUrl });
const retry: RetryService = params.getService('retry');

const listOfRequests: string[] = [];

before(async () => {
page.on('request', (request) => {
const url = request.url();
if (url.includes('/synthetics/') || url.includes('/uptime/')) {
listOfRequests.push(request.url());
}
});
await enableMonitorManagedViaApi(params.kibanaUrl);
await cleanTestMonitors(params);

Expand All @@ -48,6 +56,20 @@ journey('OverviewScrolling', async ({ page, params }) => {
expect(await invalid.isVisible()).toBeFalsy();
});

step('validates de-duplicate requests', async () => {
await page.waitForSelector(`text="test monitor 0"`);

const assertUnique = (value: string) => {
expect(listOfRequests.filter((req) => req.includes(value)).length).toBe(1);
};
assertUnique('/overview_status');
assertUnique('/overview?');
assertUnique('/service/monitors');
assertUnique('/monitor/filters');

expect(listOfRequests.length).toBe(16);
});

step('scroll until you see showing all monitors', async () => {
const gridItems = await page.locator(`[data-test-subj="syntheticsOverviewGridItem"]`);
await page.waitForSelector(`text="test monitor 0"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { useEffect, useCallback } from 'react';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useSyntheticsRefreshContext } from '../../../contexts/synthetics_refresh_context';
import { selectOverviewPageState } from '../../../state';
Expand All @@ -23,21 +23,19 @@ export function useOverviewStatus({ scopeStatusByLocation }: { scopeStatusByLoca
const { lastRefresh } = useSyntheticsRefreshContext();

const dispatch = useDispatch();
const reload = useCallback(() => {
dispatch(fetchOverviewStatusAction.get({ pageState, scopeStatusByLocation }));
}, [dispatch, pageState, scopeStatusByLocation]);

useEffect(() => {
if (loaded) {
dispatch(quietFetchOverviewStatusAction.get({ pageState, scopeStatusByLocation }));
} else {
reload();
dispatch(fetchOverviewStatusAction.get({ pageState, scopeStatusByLocation }));
}
}, [dispatch, reload, lastRefresh, pageState, loaded, scopeStatusByLocation]);
// loaded is omitted from the dependency array because it is not used in the callback
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, lastRefresh, pageState, scopeStatusByLocation]);

return {
status,
error,
reload,
};
}

0 comments on commit 70ed200

Please sign in to comment.