Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/features/ops/LiveOpsConsole.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<LiveOpsConsole subscription={baseSubscription()} />);
act(() => {
fireEvent.click(screen.getByTestId('live-ops-dockbar'));
Expand All @@ -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(<LiveOpsConsole subscription={baseSubscription()} />);
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/);
});
});

Expand Down
4 changes: 3 additions & 1 deletion src/features/ops/LiveOpsConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
</Typography>
</Box>
Expand Down
Loading