Fix sporadic failure in MarkerTest.testMarkerDeltasMoveFile#2573
Fix sporadic failure in MarkerTest.testMarkerDeltasMoveFile#2573
Conversation
The test performed two separate IFile.move() calls, creating a window
where background jobs (e.g. charset/encoding validation) could acquire
the workspace lock between the two moves and fire resource change events
that added unexpected marker deltas for subFile. This caused the
listener to record 2 changes for /MyProject/folder/subFile.txt while
the test expected exactly 1.
Fix: wrap both moves in a single IWorkspaceRunnable so the workspace
lock is held throughout both operations, preventing background jobs
from interleaving and ensuring a single coalesced event with exactly
the 4 expected changes.
To reproduce the race before the fix, run the test ~200 times in a loop:
mvn -pl resources/tests/org.eclipse.core.tests.resources \
-Pbuild-individual-bundles \
-Dtest=MarkerTest#testMarkerDeltasMoveFile \
-Dsurefire.rerunFailingTestsCount=0 \
verify
and repeat the invocation 200 times; the failure should appear within
that many iterations. With the fix, 200 runs should all succeed.
Co-authored-by: fedejeanne <2205684+fedejeanne@users.noreply.github.com>
|
@copilot are there more occurrences of this problematic pattern (moving files in separate workspace operations) through out the code that need to be looked into? If there are only a few (say 5 to 10) then prepare one draft PRs for those too and also specify how to make them fail so that we can make sure they are really problematic (I don't want to fix what isn't broken). Does this pattern repeat outside of test code too? How bad is it if this error happens in production? Give examples of possible repercussions of this error (something that can be seen in the UI?) |
After a thorough search of the test and production codebase: Other occurrences in test code? No other test in the repository has the same problematic combination: multiple sequential Does the pattern appear in production code? No. Every place in production code that performs multiple resource moves either:
So there is no production code at risk. What would happen in production if the bug existed? If production code did multiple sequential resource moves without atomicity, resource change listeners would receive one event per move rather than a single coalesced event. Between events, the workspace is in a partially-moved state. Concrete UI consequences:
|
Two sequential
IFile.move()calls left a window between operations where background jobs (charset/encoding validation) could acquire the workspace lock, fire resource change events againstsubFile, and cause the listener to record 2 marker deltas for/MyProject/folder/subFile.txtinstead of the expected 1 — resulting in a sporadic assertion failure.Fix
Wrap both moves in a single
IWorkspaceRunnableto hold the workspace lock across both operations, preventing background jobs from interleaving and ensuring a single coalesced event with exactly the 4 expected changes:Reproducing the race (before fix)
The failure should manifest within ~200 iterations; with the fix all 200 should pass.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.