Repository navigation
Let the real-PowerShell usage tests survive a slow runner - #153
Conversation
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
left a comment
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
|
Taken: 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.
|
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
left a comment
There was a problem hiding this comment.
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.
tests/usage.test.ts > PowerShellQuery > reads CPU time and memory of a real processfailed 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, soqueryanswered[]exactly as designed andexpect(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
startTimeoutMsof 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 insrc/changes, so the app's own 30 s is untouched.Testing
npm test: 180 pass,tests/usage.test.tsin 3.7 s locally (unchanged, the new numbers only matter when something is slow)npm run typecheck