From baee13f90c980a5e39d926e2dc23adea04271d99 Mon Sep 17 00:00:00 2001 From: OrcaWin <293788423+OrcaWin@users.noreply.github.com> Date: Sun, 9 Aug 2026 22:07:32 -0700 Subject: [PATCH] test: balance clipboard cleanup benchmark order --- ...lipboard-remote-file-cleanup.bench.test.ts | 45 ++++++++++++++----- .../clipboard-remote-file-staging.test.ts | 8 +++- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/window/clipboard-remote-file-cleanup.bench.test.ts b/src/main/window/clipboard-remote-file-cleanup.bench.test.ts index ea187ca9c40..56de7233a29 100644 --- a/src/main/window/clipboard-remote-file-cleanup.bench.test.ts +++ b/src/main/window/clipboard-remote-file-cleanup.bench.test.ts @@ -10,7 +10,7 @@ import { const BENCH_ENABLED = process.env.ORCA_CLIPBOARD_CLEANUP_BENCH === '1' const FOREIGN_ENTRY_COUNT = Number(process.env.ORCA_CLIPBOARD_CLEANUP_BENCH_ENTRIES ?? 100_000) const WARMUP_RUNS = 3 -const SAMPLE_RUNS = 25 +const SAMPLE_RUNS_PER_ARM = 24 const FIXTURE_PREFIX = 'orca-clipboard-cleanup-bench-' const NOW_MS = 1_760_000_000_000 @@ -61,20 +61,42 @@ describe.skipIf(!BENCH_ENABLED)('remote clipboard cleanup benchmark', () => { await cleanupExpiredRemoteClipboardStaging(fixtureRoot, NOW_MS) } - const sharedRootSamples: number[] = [] - const ownedParentSamples: number[] = [] - for (let index = 0; index < SAMPLE_RUNS; index += 1) { - sharedRootSamples.push(await measure(() => scanSharedTempRoot(fixtureRoot))) - ownedParentSamples.push( - await measure(() => cleanupExpiredRemoteClipboardStaging(fixtureRoot, NOW_MS)) - ) + const samples = { ownedParent: [] as number[], sharedRoot: [] as number[] } + const launchPositions = { + ownedParent: [0, 0], + sharedRoot: [0, 0] + } + for (let index = 0; index < SAMPLE_RUNS_PER_ARM; index += 1) { + const order = + index % 2 === 0 + ? (['sharedRoot', 'ownedParent'] as const) + : (['ownedParent', 'sharedRoot'] as const) + for (const [position, arm] of order.entries()) { + launchPositions[arm][position] += 1 + samples[arm].push( + await measure(() => + arm === 'sharedRoot' + ? scanSharedTempRoot(fixtureRoot) + : cleanupExpiredRemoteClipboardStaging(fixtureRoot, NOW_MS) + ) + ) + } } + expect(launchPositions).toEqual({ + ownedParent: [SAMPLE_RUNS_PER_ARM / 2, SAMPLE_RUNS_PER_ARM / 2], + sharedRoot: [SAMPLE_RUNS_PER_ARM / 2, SAMPLE_RUNS_PER_ARM / 2] + }) + expect(samples.ownedParent).toHaveLength(SAMPLE_RUNS_PER_ARM) + expect(samples.sharedRoot).toHaveLength(SAMPLE_RUNS_PER_ARM) expect(await countForeignEntries(fixtureRoot)).toBe(FOREIGN_ENTRY_COUNT) await expect(access(freshTransfer)).resolves.toBeUndefined() - const sharedRoot = summarize(sharedRootSamples) - const ownedParent = summarize(ownedParentSamples) + const sharedRoot = summarize(samples.sharedRoot) + const ownedParent = summarize(samples.ownedParent) console.log('correctness=pass') + console.log( + `sampling=ABBA positions-per-arm=${SAMPLE_RUNS_PER_ARM / 2}/${SAMPLE_RUNS_PER_ARM / 2} p95-order-drift<=1-slot` + ) console.log(`post12917-shared-root median=${sharedRoot.median}ms p95=${sharedRoot.p95}ms`) console.log(`owned-parent median=${ownedParent.median}ms p95=${ownedParent.p95}ms`) }, 900_000) @@ -117,7 +139,8 @@ async function measure(operation: () => Promise): Promise { function summarize(samples: number[]): { median: string; p95: string } { const sorted = [...samples].sort((left, right) => left - right) - const median = sorted[Math.ceil(sorted.length * 0.5) - 1] + const middle = sorted.length / 2 + const median = (sorted[middle - 1] + sorted[middle]) / 2 const p95 = sorted[Math.ceil(sorted.length * 0.95) - 1] return { median: median.toFixed(3), p95: p95.toFixed(3) } } diff --git a/src/main/window/clipboard-remote-file-staging.test.ts b/src/main/window/clipboard-remote-file-staging.test.ts index d9b42fa6dce..b56de7be665 100644 --- a/src/main/window/clipboard-remote-file-staging.test.ts +++ b/src/main/window/clipboard-remote-file-staging.test.ts @@ -248,10 +248,15 @@ describe('legacy remote clipboard staging compatibility', () => { writeFileMock.mockResolvedValue(undefined) }) - it('caps a large foreign-root scan at 4096 total entries', async () => { + it('marks migration complete when a legacy child falls beyond the 4096-entry window', async () => { let visited = 0 + let reachedLateLegacyChild = false function* foreignEntries(): Generator { for (let index = 0; index < 200_000; index += 1) { + if (index === 4_096) { + reachedLateLegacyChild = true + yield directoryEntry(LEGACY_EXPIRED) + } visited += 1 yield directoryEntry(`foreign-${index}`, index % 2 === 0) } @@ -261,6 +266,7 @@ describe('legacy remote clipboard staging compatibility', () => { await cleanupLegacyRemoteClipboardStaging(TEMP_ROOT, NOW_MS) expect(visited).toBe(4_096) + expect(reachedLateLegacyChild).toBe(false) expect(lstatMock).toHaveBeenCalledOnce() expect(rmMock).not.toHaveBeenCalled() expect(writeFileMock).toHaveBeenCalledWith(MARKER_PATH, '', {