From 665101e7a3fa55ebc9a092644fac12ec31bc6a37 Mon Sep 17 00:00:00 2001 From: Andrew Baldwin Date: Fri, 29 Nov 2024 15:38:44 -0500 Subject: [PATCH 1/2] Fix ui shows wrong number of requests --- locust/webui/eslint.config.mjs | 15 ++++++++------- locust/webui/src/hooks/useFetchStats.ts | 15 ++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/locust/webui/eslint.config.mjs b/locust/webui/eslint.config.mjs index 304cddc8b5..b8f34e519a 100644 --- a/locust/webui/eslint.config.mjs +++ b/locust/webui/eslint.config.mjs @@ -1,15 +1,16 @@ -import react from 'eslint-plugin-react'; -import reactHooks from 'eslint-plugin-react-hooks'; +import { fixupPluginRules } from '@eslint/compat'; +import { FlatCompat } from '@eslint/eslintrc'; +import js from '@eslint/js'; import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +import _import from 'eslint-plugin-import'; import prettier from 'eslint-plugin-prettier'; +import react from 'eslint-plugin-react'; +import reactHooks from 'eslint-plugin-react-hooks'; import unusedImports from 'eslint-plugin-unused-imports'; -import _import from 'eslint-plugin-import'; -import { fixupPluginRules } from '@eslint/compat'; -import tsParser from '@typescript-eslint/parser'; + import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import js from '@eslint/js'; -import { FlatCompat } from '@eslint/eslintrc'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/locust/webui/src/hooks/useFetchStats.ts b/locust/webui/src/hooks/useFetchStats.ts index c227fea5af..04bf8fac29 100644 --- a/locust/webui/src/hooks/useFetchStats.ts +++ b/locust/webui/src/hooks/useFetchStats.ts @@ -24,12 +24,13 @@ export default function useFetchStats() { const shouldRunRefetchInterval = swarm.state === SWARM_STATE.SPAWNING || swarm.state == SWARM_STATE.RUNNING; - const updateStats = () => { + useEffect(() => { if (!statsData) { return; } const { + state, currentResponseTimePercentiles, extendedStats, stats, @@ -80,17 +81,9 @@ export default function useFetchStats() { userCount, }); updateCharts(newChartEntry); - }; - useEffect(() => { - if (statsData) { - setSwarm({ state: statsData.state }); - } - }, [statsData && statsData.state]); - - useInterval(updateStats, STATS_REFETCH_INTERVAL, { - shouldRunInterval: !!statsData && shouldRunRefetchInterval, - }); + setSwarm({ state }); + }, [statsData]); useInterval(refetchStats, STATS_REFETCH_INTERVAL, { shouldRunInterval: shouldRunRefetchInterval, From 2760b742453492c374f77dcbef6a7f77a9b88377 Mon Sep 17 00:00:00 2001 From: Andrew Baldwin Date: Sat, 30 Nov 2024 10:18:17 -0500 Subject: [PATCH 2/2] Remove extra wait time from tests --- locust/webui/src/hooks/tests/useFetchStats.test.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/locust/webui/src/hooks/tests/useFetchStats.test.tsx b/locust/webui/src/hooks/tests/useFetchStats.test.tsx index 9561306be9..16f22ca887 100644 --- a/locust/webui/src/hooks/tests/useFetchStats.test.tsx +++ b/locust/webui/src/hooks/tests/useFetchStats.test.tsx @@ -38,9 +38,6 @@ describe('useFetchStats', () => { swarm: { state: SWARM_STATE.RUNNING }, }); - await act(async () => { - await vi.advanceTimersByTimeAsync(2000); - }); await act(async () => { await vi.advanceTimersByTimeAsync(2000); }); @@ -67,9 +64,6 @@ describe('useFetchStats', () => { store.dispatch(swarmActions.setSwarm({ state: SWARM_STATE.RUNNING })); }); - await act(async () => { - await vi.advanceTimersByTimeAsync(2000); - }); await act(async () => { await vi.advanceTimersByTimeAsync(2000); });