test(hooks): the held-lock guard tests keep one loose timing check - #396
Merged
Merged
Conversation
The three held-lock tests in tests/hooks/guard-check.test.ts asserted three timings, among them a floor: the locked run had to take more than 100 ms longer than an unlocked run, to prove the counter waits at all. That difference is the difference of two process starts, and on a slow Windows runner it swings by more than 100 ms: CI failed at random there (93 ms measured, more than 100 required) while the hook behaved correctly. Nobody using MeMesh can tell 0.2 s from 0.5 s, so the exact wait is not worth a test that fails at random. The tests keep everything that matters to a user (the guard warning is delivered on stdout, the hook exits 0, stderr says the fire was not counted) and one loose timing check: a locked run may not take a second longer than an unlocked run. That still fails with the old 2 s wait (about 2150 ms measured with the wait set back to 2000, limit 1000; three tests red). The floor, the ceiling derived from the hook's timeout, the hookBudgetMs helper, the second unlocked reference run and the HOOK_BUSY_TIMEOUT_MS import are removed. Test-only change. Refs #366
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #366. Test-only change, one file (
tests/hooks/guard-check.test.ts).Problem
The three held-lock tests (a second database connection holds the write lock while a real guard hook runs) asserted three timings. One of them was a floor: the locked run had to take more than 100 ms longer than an unlocked run, to prove the fire counter waits at all. That difference is the difference of two process starts, and on a slow Windows CI runner it swings by more than 100 ms, so the test failed at random there (93 ms measured, more than 100 required, on PR #395) while the hook behaved correctly. No user can tell a 0.2 s wait from a 0.5 s one, so the exact wait is not worth a test that fails at random.
Change
hookBudgetMshelper, the second unlocked reference run and theHOOK_BUSY_TIMEOUT_MSimport.Evidence
locked - unlockedat 200 ms: 202-250 ms over several runs, including under CPU load, against the 1000 ms limit.npm run verifygreen on the tip tree.Known trade-off
Nothing in the tests now pins that the counter waits at all (with the wait at 0 the file still passes). That is deliberate, see the Problem section. Also noted by the reviewers, present before this change and left alone: the comment on
GUARD_COUNTER_WAIT_MSinscripts/hooks/_shared.jssays the tests read the constant (they do not), and the ledger assertion in the Bash held-lock test reads the last ledger line, which can be the unlocked run's record.