Skip to content

Commit 535b055

Browse files
Copilotfedejeanne
andcommitted
Fix sporadic MarkerTest.testMarkerDeltasMoveFile failure
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>
1 parent 519a3b0 commit 535b055

File tree

1 file changed

+7
-3
lines changed
  • resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources

1 file changed

+7
-3
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MarkerTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,13 @@ public void testMarkerDeltasMoveFile(TestInfo testInfo) throws CoreException {
969969
IMarker subFileMarker = subFile.createMarker(IMarker.BOOKMARK);
970970
listener.reset();
971971

972-
// move the files
973-
file.move(destFile.getFullPath(), IResource.FORCE, createTestMonitor());
974-
subFile.move(destSubFile.getFullPath(), IResource.FORCE, createTestMonitor());
972+
// move the files in one atomic workspace operation to prevent background jobs
973+
// (e.g. charset/encoding validation) from running between the two moves and
974+
// adding unexpected marker changes to the listener
975+
getWorkspace().run(monitor -> {
976+
file.move(destFile.getFullPath(), IResource.FORCE, monitor);
977+
subFile.move(destSubFile.getFullPath(), IResource.FORCE, monitor);
978+
}, createTestMonitor());
975979

976980
// verify marker deltas
977981
listener.assertNumberOfAffectedResources(4);

0 commit comments

Comments
 (0)