test(config): make HasLoadedConfigurationBeenModified deterministic - #1786
Draft
nikolauspschuetz wants to merge 1 commit into
Draft
test(config): make HasLoadedConfigurationBeenModified deterministic#1786nikolauspschuetz wants to merge 1 commit into
nikolauspschuetz wants to merge 1 commit into
Conversation
The two subtests each slept a full second so a rewritten file's mod time (second precision) would advance past the load time. Advance the mod time explicitly with os.Chtimes instead, and give the directory subtest its own temp dir so the file subtest's future-dated config.yaml no longer leaks into it. Removes ~2s of wall-clock sleep and the coarse-clock dependence; the test is now deterministic.
Owner
|
Makes sense to me. Ping me when it's no longer in draft |
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.
TestConfig_HasLoadedConfigurationBeenModifiedslept a hardtime.Sleep(time.Second)in each of its two subtests, purely so a rewritten file's mod time (second precision) would tick past the load time — ~2s of dead wall-clock per run, coupling the assertion to real elapsed time rather than the code under test.This advances the modified file's mod time explicitly with
os.Chtimes(...)instead, and gives the directory subtest its ownt.TempDir()— otherwise the file subtest's now-future-datedconfig.yaml(the two subtests shared one dir) leaks in and makes the directory subtest's initial "not modified" check fail.Result: no sleep, no wall-clock dependence, deterministic — verified with
go test ./config/ -run TestConfig_HasLoadedConfigurationBeenModified -race -count=10(10/10 pass).Developed with AI assistance (Claude Code); I directed, reviewed, and verified it locally.