diff --git a/src/features/ops/LiveOpsConsole.test.tsx b/src/features/ops/LiveOpsConsole.test.tsx index 3527c04..0e76066 100644 --- a/src/features/ops/LiveOpsConsole.test.tsx +++ b/src/features/ops/LiveOpsConsole.test.tsx @@ -64,7 +64,7 @@ describe('LiveOpsConsole', () => { }); }); - it('shows per-procedure latency rows with recorded samples', async () => { + it('shows the last sample instead of repeated percentiles when fewer than 5 samples are recorded', async () => { renderWithTheme(); act(() => { fireEvent.click(screen.getByTestId('live-ops-dockbar')); @@ -73,14 +73,41 @@ describe('LiveOpsConsole', () => { fireEvent.click(screen.getByTestId('live-ops-tab-latency')); }); act(() => { - latencyStore.record('deals.getActivityOfferPlacements', 50); - latencyStore.record('deals.getActivityOfferPlacements', 150); + latencyStore.record('deals.getActivityOfferPlacements', 1182); }); await waitFor(() => { - expect( - screen.getByTestId('latency-row-deals.getActivityOfferPlacements').textContent, - ).toMatch(/n=2/); + const text = screen.getByTestId( + 'latency-row-deals.getActivityOfferPlacements', + ).textContent; + expect(text).toMatch(/n=1/); + expect(text).toMatch(/last 1182 ms/); + expect(text).not.toMatch(/p50/); + }); + }); + + it('shows p50/p95/p99 once at least 5 samples are recorded', async () => { + renderWithTheme(); + act(() => { + fireEvent.click(screen.getByTestId('live-ops-dockbar')); + }); + act(() => { + fireEvent.click(screen.getByTestId('live-ops-tab-latency')); + }); + act(() => { + for (const ms of [10, 20, 30, 40, 50]) { + latencyStore.record('deals.getActivityOfferPlacements', ms); + } + }); + + await waitFor(() => { + const text = screen.getByTestId( + 'latency-row-deals.getActivityOfferPlacements', + ).textContent; + expect(text).toMatch(/n=5/); + expect(text).toMatch(/p50/); + expect(text).toMatch(/p95/); + expect(text).toMatch(/p99/); }); }); diff --git a/src/features/ops/LiveOpsConsole.tsx b/src/features/ops/LiveOpsConsole.tsx index aa69ec4..08fedd2 100644 --- a/src/features/ops/LiveOpsConsole.tsx +++ b/src/features/ops/LiveOpsConsole.tsx @@ -369,7 +369,9 @@ function LatencyRow({ data-testid={`latency-row-${label}`} > {hasData - ? `n=${summary.n} p50 ${formatMs(summary.p50)} p95 ${formatMs(summary.p95)} p99 ${formatMs(summary.p99)}` + ? summary.n < 5 + ? `n=${summary.n} last ${formatMs(summary.last ?? 0)}` + : `n=${summary.n} p50 ${formatMs(summary.p50)} p95 ${formatMs(summary.p95)} p99 ${formatMs(summary.p99)}` : 'no samples'}