Skip to content

Fix flaky mtime-ordering bug in CSharpSyntaxTreeCacheTests - #498

Merged
clrudolphi merged 1 commit into
masterfrom
fix/csharp-syntax-tree-cache-test-mtime-order
Aug 27, 2026
Merged

Fix flaky mtime-ordering bug in CSharpSyntaxTreeCacheTests#498
clrudolphi merged 1 commit into
masterfrom
fix/csharp-syntax-tree-cache-test-mtime-order

Conversation

@clrudolphi

Copy link
Copy Markdown
Collaborator

🤔 What's changed?

GetOrParseFromDisk_re_parses_after_the_file_is_rewritten set the file's last-write-time two seconds into the future, then called File.WriteAllText — which itself resets the mtime to the real current time as part of the write, undoing the deliberate bump the comment claimed would "ensure a distinct last-write-time even on filesystems with coarse mtime resolution." On an unlucky run the two writes' real timestamps can round to the same tick, so CSharpSyntaxTreeCache.GetOrParseFromDisk wrongly treats the rewritten file as unchanged and returns the stale cached parse — failing the test's second.Should().NotBeSameAs(first) assertion.

Swapped the order: write the new content first, then bump the mtime afterward, so the future timestamp actually sticks.

⚡️ What's your motivation?

Hit this failing in CI on PR #497, an unrelated change — confirmed the file isn't touched by that PR's diff at all. Traced it to this pre-existing ordering bug in the test itself.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

🧩 Area(s) touched

  • LSP server (src/LSP) — test-only change

♻️ Anything particular you want feedback on?

Verified stable over 20 repeated local runs plus the full Reqnroll.IdeSupport.LSP.Core.Tests suite (684/685, 1 pre-existing unrelated skip). Since the failure was timing-dependent, I can't fully guarantee it'll never recur under sufficiently degenerate CI clock/filesystem conditions, but this closes the concrete ordering bug that caused it.

📋 Checklist:

  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes. (test-only fix; no new test needed — the existing test now correctly exercises the intended behavior)

🤖 Generated with Claude Code

GetOrParseFromDisk_re_parses_after_the_file_is_rewritten set the file's last-write-time
to two seconds in the future, then called File.WriteAllText -- which itself resets the
mtime to the real current time as part of the write, undoing the bump that was supposed
to guarantee a distinct timestamp on filesystems with coarse mtime resolution. On an
unlucky run the two writes' real timestamps can round to the same tick, so
CSharpSyntaxTreeCache wrongly treats the rewritten file as unchanged and returns the
stale cached parse -- exactly the failure seen in CI on PR #497 (an unrelated change):
https://github.com/reqnroll/Reqnroll.IdeSupport/actions/runs/33029407365/job/98378590600

Swapped the order -- write first, then bump the mtime -- so the deliberate future
timestamp actually sticks. Verified stable over 20 repeated runs; full
Reqnroll.IdeSupport.LSP.Core.Tests suite still green (684/685, 1 pre-existing skip).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@clrudolphi
clrudolphi merged commit f164425 into master Aug 27, 2026
17 checks passed
@clrudolphi
clrudolphi deleted the fix/csharp-syntax-tree-cache-test-mtime-order branch August 27, 2026 01:56
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.

1 participant