mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 22:15:40 +00:00
81f900c7a6
* perf(analysis): measure tpm over trailing 5s instead of full minute Mirror the cover cpm change: a 60s rolling average added too much inertia and flattened real bursts/stalls. Count completions in the trailing 5s window and extrapolate to per-minute, so analysis tpm reacts promptly and decays to 0 within the window when idle. Retention stays at 60s. * docs(changelog): note trailing-window throughput rate (PR #948)
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest';
|
||
import {
|
||
getAnalysisTracksPerMinute,
|
||
recordAnalysisTrackPerf,
|
||
resetAnalysisPerfStateForTest,
|
||
} from './analysisPerfStore';
|
||
|
||
beforeEach(() => {
|
||
resetAnalysisPerfStateForTest();
|
||
});
|
||
|
||
afterEach(() => {
|
||
vi.useRealTimers();
|
||
});
|
||
|
||
describe('analysisPerfStore', () => {
|
||
const record = (trackId: string): void =>
|
||
recordAnalysisTrackPerf({ trackId, fetchMs: 1, seedMs: 1, bpmMs: 1, totalMs: 3 });
|
||
|
||
it('records last track timings and trailing-window tpm', () => {
|
||
vi.useFakeTimers();
|
||
vi.setSystemTime(1_000_000);
|
||
record('t1');
|
||
vi.advanceTimersByTime(100);
|
||
// 1 completion in the trailing 5s → 1 / 5s × 60 = 12 tpm.
|
||
expect(getAnalysisTracksPerMinute()).toBeCloseTo(12, 0);
|
||
});
|
||
|
||
it('extrapolates a burst over the trailing 5s window', () => {
|
||
vi.useFakeTimers();
|
||
vi.setSystemTime(2_000_000);
|
||
record('a');
|
||
vi.advanceTimersByTime(1_000);
|
||
record('b');
|
||
vi.advanceTimersByTime(1_000);
|
||
record('c');
|
||
// 3 completions within the last 5s → 3 / 5s × 60 = 36 tpm.
|
||
expect(getAnalysisTracksPerMinute()).toBeCloseTo(36, 0);
|
||
});
|
||
|
||
it('decays to 0 once completions fall outside the trailing window', () => {
|
||
vi.useFakeTimers();
|
||
vi.setSystemTime(3_000_000);
|
||
record('old');
|
||
expect(getAnalysisTracksPerMinute()).toBeGreaterThan(0);
|
||
vi.advanceTimersByTime(6_000);
|
||
expect(getAnalysisTracksPerMinute()).toBe(0);
|
||
});
|
||
});
|