From 2337bc0c620ac488d2c9cfd2b2ae045b9623f1ff Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:28:28 -0500 Subject: [PATCH 1/2] Let the real-PowerShell usage tests survive a slow runner tests/usage.test.ts > reads CPU time and memory of a real process failed in CI: the first answer from a new PowerShell did not arrive within the app's 30 s start timeout, so the query answered [] as it is meant to and the assertion failed. 30 s is right for the app, where a desktop that slow has something wrong with it and the next sample tries again, but these three tests are about the answers, not the timeout. They now pass a 90 s start timeout and a test timeout above it, so a slow start shows up as a slow test rather than a red run. --- tests/usage.test.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/usage.test.ts b/tests/usage.test.ts index 021f8a7..3081b71 100644 --- a/tests/usage.test.ts +++ b/tests/usage.test.ts @@ -96,9 +96,19 @@ describe('UsageSampler', () => { }) }) +/** + * The app gives a new PowerShell 30 s to hand back its first answer and replaces it after that, + * which is right for the app: a desktop that slow has something wrong with it and the next sample + * tries again. A GitHub Windows runner does go over 30 s, cold, often enough to fail a run, and + * these tests are about the answers rather than that timeout, so they allow a lot more. + */ +const START_MS = 90_000 +/** longer than START_MS, so a slow start fails on the assertion and not on the test timing out */ +const TEST_MS = 120_000 + describe.skipIf(process.platform !== 'win32')('PowerShellQuery', () => { it('reads CPU time and memory of a real process', async () => { - const q = new PowerShellQuery() + const q = new PowerShellQuery(10_000, START_MS) try { const rows = await q.query([process.pid]) expect(rows).toHaveLength(1) @@ -110,20 +120,20 @@ describe.skipIf(process.platform !== 'win32')('PowerShellQuery', () => { } finally { q.close() } - }, 60_000) + }, TEST_MS) it('gives a new PowerShell longer to start than an answer may take', async () => { // 1 ms is far too short for any answer, but the first one only has to beat the start timeout - const q = new PowerShellQuery(1, 30_000) + const q = new PowerShellQuery(1, START_MS) try { expect(await q.query([process.pid])).toHaveLength(1) } finally { q.close() } - }, 60_000) + }, TEST_MS) it('a closed PowerShell exiting late does not answer the next question', async () => { - const q = new PowerShellQuery() + const q = new PowerShellQuery(10_000, START_MS) try { await q.query([process.pid]) // starts a PowerShell q.close() // killed, its exit event comes a bit later @@ -132,7 +142,8 @@ describe.skipIf(process.platform !== 'win32')('PowerShellQuery', () => { } finally { q.close() } - }, 90_000) + // two cold starts in a row + }, TEST_MS * 2) it('gives up on a PowerShell that does not answer in time', async () => { const q = new PowerShellQuery(1, 1) // no PowerShell starts in 1 ms From 8a632e941ca5e4ec0d5421c9e30347973a73ab37 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:30:02 -0500 Subject: [PATCH 2/2] Take the test timeouts from the app's own numbers The two constructor calls repeated the default answer timeout to reach the second argument, and the comment repeated the start timeout in words. usage.ts exports both now, so the tests say three times what the app allows instead of a number that has to be kept in step. --- src/main/usage.ts | 18 +++++++++++------- tests/usage.test.ts | 18 +++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/usage.ts b/src/main/usage.ts index a44bbcc..b918ff2 100644 --- a/src/main/usage.ts +++ b/src/main/usage.ts @@ -28,19 +28,23 @@ while ($true) { ` /** Asks a background PowerShell for CPU time and memory of some processes. */ +/** how long an answer from a PowerShell that is already running may take */ +export const ANSWER_TIMEOUT_MS = 10_000 +/** + * for the first answer of a new PowerShell, which also waits for it to start. That alone can take + * over 10 s on a busy or slow PC, and with the normal timeout every new PowerShell was killed + * before its first answer, so usage never showed up there at all + */ +export const START_TIMEOUT_MS = 30_000 + export class PowerShellQuery implements ProcessQuery { private ps: ChildProcessWithoutNullStreams | null = null private buf = '' private waiting: ((rows: ProcRow[]) => void) | null = null constructor( - private readonly timeoutMs = 10_000, - /** - * for the first question of a new PowerShell, which also waits for it to start. That alone can - * take over 10 s on a busy or slow PC, and with the normal timeout every new PowerShell was - * killed before its first answer, so usage never showed up there at all - */ - private readonly startTimeoutMs = 30_000 + private readonly timeoutMs = ANSWER_TIMEOUT_MS, + private readonly startTimeoutMs = START_TIMEOUT_MS ) {} query(pids: number[]): Promise { diff --git a/tests/usage.test.ts b/tests/usage.test.ts index 3081b71..37066af 100644 --- a/tests/usage.test.ts +++ b/tests/usage.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' import type { VmUsage } from '@shared/ipc' -import { cpuPercent, PowerShellQuery, UsageSampler, type ProcessQuery, type ProcRow } from '../src/main/usage' +import { ANSWER_TIMEOUT_MS, cpuPercent, PowerShellQuery, START_TIMEOUT_MS, UsageSampler, type ProcessQuery, type ProcRow } from '../src/main/usage' describe('cpuPercent', () => { it('is zero on the first sample', () => { @@ -97,18 +97,18 @@ describe('UsageSampler', () => { }) /** - * The app gives a new PowerShell 30 s to hand back its first answer and replaces it after that, - * which is right for the app: a desktop that slow has something wrong with it and the next sample - * tries again. A GitHub Windows runner does go over 30 s, cold, often enough to fail a run, and - * these tests are about the answers rather than that timeout, so they allow a lot more. + * The app replaces a new PowerShell that hasn't answered within START_TIMEOUT_MS, which is right + * for the app: a desktop that slow has something wrong with it and the next sample tries again. A + * cold GitHub Windows runner does go over it often enough to fail a run, and these tests are about + * the answers rather than that timeout, so they allow three times as long. */ -const START_MS = 90_000 +const START_MS = START_TIMEOUT_MS * 3 /** longer than START_MS, so a slow start fails on the assertion and not on the test timing out */ -const TEST_MS = 120_000 +const TEST_MS = START_MS + 30_000 describe.skipIf(process.platform !== 'win32')('PowerShellQuery', () => { it('reads CPU time and memory of a real process', async () => { - const q = new PowerShellQuery(10_000, START_MS) + const q = new PowerShellQuery(ANSWER_TIMEOUT_MS, START_MS) try { const rows = await q.query([process.pid]) expect(rows).toHaveLength(1) @@ -133,7 +133,7 @@ describe.skipIf(process.platform !== 'win32')('PowerShellQuery', () => { }, TEST_MS) it('a closed PowerShell exiting late does not answer the next question', async () => { - const q = new PowerShellQuery(10_000, START_MS) + const q = new PowerShellQuery(ANSWER_TIMEOUT_MS, START_MS) try { await q.query([process.pid]) // starts a PowerShell q.close() // killed, its exit event comes a bit later