Skip to content

test(config): make HasLoadedConfigurationBeenModified deterministic - #1786

Draft
nikolauspschuetz wants to merge 1 commit into
TwiN:masterfrom
nikolauspschuetz:test-config-modified-deterministic
Draft

test(config): make HasLoadedConfigurationBeenModified deterministic#1786
nikolauspschuetz wants to merge 1 commit into
TwiN:masterfrom
nikolauspschuetz:test-config-modified-deterministic

Conversation

@nikolauspschuetz

Copy link
Copy Markdown
Contributor

TestConfig_HasLoadedConfigurationBeenModified slept a hard time.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 own t.TempDir() — otherwise the file subtest's now-future-dated config.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.

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.
@TwiN

TwiN commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Makes sense to me. Ping me when it's no longer in draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants