Skip to content

Let the real-PowerShell usage tests survive a slow runner - #153

Merged
A21-devs merged 2 commits into
mainfrom
tests/powershell-slow-start
Dec 4, 2026
Merged

A21-devs merged 2 commits into
mainfrom
tests/powershell-slow-start

Conversation

@A21-devs

@A21-devs A21-devs commented Dec 4, 2026

Copy link
Copy Markdown
Owner

tests/usage.test.ts > PowerShellQuery > reads CPU time and memory of a real process failed on the CI run for #151 (job): the first answer from a new PowerShell didn't arrive inside the app's 30 s start timeout, so query answered [] exactly as designed and expect(rows).toHaveLength(1) failed 30 s in. A rerun of the same commit was green.

The 30 s default is right for the app: a desktop where a PowerShell needs longer than that has something wrong with it, and the sampler tries again with a fresh one two seconds later. A cold GitHub Windows runner does cross it, though, often enough to turn up in a day's runs.

The three tests that start a real PowerShell now pass startTimeoutMs of 90 s and a test timeout above that, so a slow start makes the test slow instead of red. The one that checks the start timeout beats a tiny answer timeout still does exactly that, with the bigger number. Nothing in src/ changes, so the app's own 30 s is untouched.

Testing

  • npm test: 180 pass, tests/usage.test.ts in 3.7 s locally (unchanged, the new numbers only matter when something is slow)
  • npm run typecheck

@A21-devs A21-devs added the tests label Dec 4, 2026
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.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnosis matches the job log: 30009 ms and an empty result, which is query doing what it is told, so the test was asserting the runner was fast rather than that the query works. Keeping the app at 30 s and loosening only the tests is the right way round.

One thing I thought about and am leaving: after this, no test exercises the shipped 30 s default, since all three real-PowerShell tests now pass their own. That is the trade for not having a test whose pass depends on runner speed, and the fake-query tests still cover what the sampler does when an answer never comes. Worth saying out loud, though, because a future change to the default would not be caught by anything here.

Comment thread tests/usage.test.ts Outdated
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)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 10_000 here and on line 136 is the constructor's own default for timeoutMs, repeated so the second argument can be reached. If that default ever changes, these two keep the old number silently, and the comment above says "the app gives a new PowerShell 30 s" where 30 s is another copy of a number that lives in usage.ts.

Exporting both defaults from usage.ts and using them as the constructor's defaults would let this read new PowerShellQuery(ANSWER_TIMEOUT_MS, START_TIMEOUT_MS * 3), which says what it means (three times what the app allows) and follows the app if either number moves.

@A21-devs

A21-devs commented Dec 4, 2026

Copy link
Copy Markdown
Owner Author

Taken: usage.ts exports ANSWER_TIMEOUT_MS (10 s) and START_TIMEOUT_MS (30 s) and uses them as the constructor defaults, so the tests now read new PowerShellQuery(ANSWER_TIMEOUT_MS, START_TIMEOUT_MS * 3) and the comment points at the constant instead of repeating 30 s in words. TEST_MS is START_MS + 30_000 for the same reason.

That also closes the gap you raised a little: the tests follow the shipped number now, so lowering the app's default makes them allow less rather than drift away from it.

npm run typecheck, npm test (180), npm run build after the change.

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.

@A21-devs A21-devs left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass over the last commit. The finding is fixed and a bit further than asked: both defaults are named constants in usage.ts, the constructor takes its defaults from them, and the tests express their own numbers as START_TIMEOUT_MS * 3 and START_MS + 30_000, so there is no copy of either number left in the test file. The doc comment that explained the start timeout moved onto the constant, which is where it belongs now that the constant is what other files read.

Checked the rest of the file still lines up: the fake-query tests are untouched and don't use either constant, new PowerShellQuery(1, 1) in the give-up test still deliberately passes its own tiny numbers, and npm test reports the same 180.

Nothing else outstanding.

@A21-devs
A21-devs merged commit 2f25b29 into main Dec 4, 2026
1 check passed
@A21-devs
A21-devs deleted the tests/powershell-slow-start branch December 4, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant