Skip to content

Commit 6d2b614

Browse files
vogellaclaude
andcommitted
Fix flaky FileSearchTests.testBinaryContentTypeWithDescriber race condition
The test was failing intermittently (1 out of 3 runs) due to a race condition in content type registration. The test dynamically registers a binary content type but files were created and searched before the content type was fully available, causing the binary file to be incorrectly included in search results. This fix adds: 1. Explicit wait loop to verify content type is registered before proceeding (up to 500ms with 10ms intervals) 2. Force content type detection on files after creation by calling getContentDescription() to ensure binary signature describer is properly applied Verified with 5 consecutive test runs - all passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 601b0d3 commit 6d2b614

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/FileSearchTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.eclipse.core.runtime.IContributor;
3636
import org.eclipse.core.runtime.IExtensionRegistry;
3737
import org.eclipse.core.runtime.Platform;
38+
import org.eclipse.core.runtime.content.IContentType;
39+
import org.eclipse.core.runtime.content.IContentTypeManager;
3840

3941
import org.eclipse.core.resources.IFile;
4042
import org.eclipse.core.resources.IFolder;
@@ -601,12 +603,31 @@ private void testBinaryContentTypeWithDescriber(TestResultCollector collector) t
601603
.forEach(extension -> registry.removeExtension(extension, masterToken));
602604
}) {
603605

606+
// Wait for content type to be registered and available
607+
// This prevents race conditions where the content type might not be immediately available
608+
IContentTypeManager contentTypeManager= Platform.getContentTypeManager();
609+
IContentType binaryContentType= null;
610+
for (int i= 0; i < 50 && binaryContentType == null; i++) {
611+
binaryContentType= contentTypeManager.getContentType("org.eclipse.search.tests.binaryFile");
612+
if (binaryContentType == null) {
613+
Thread.sleep(10); // Wait 10ms before retrying
614+
}
615+
}
616+
if (binaryContentType == null) {
617+
throw new AssertionError("Content type 'org.eclipse.search.tests.binaryFile' was not registered");
618+
}
619+
604620
// Use unique folder name to avoid conflicts with other tests running in parallel
605621
String uniqueFolderName= "binaryContentTypeTest-" + java.util.UUID.randomUUID().toString();
606622
IFolder folder= ResourceHelper.createFolder(fProject.getFolder(uniqueFolderName));
607623
IFile textfile= ResourceHelper.createFile(folder, "textfile", "text hello");
608624
IFile binaryfile= ResourceHelper.createFile(folder, "binaryfile", "binary hello");
609625

626+
// Force content type detection on files to ensure the newly registered content type is applied
627+
// This helps avoid race conditions where the content type might not be immediately available
628+
textfile.getContentDescription();
629+
binaryfile.getContentDescription();
630+
610631
Pattern searchPattern= PatternConstructor.createPattern("hello", true, false);
611632

612633
// Search only in the unique folder to avoid interference from other tests

0 commit comments

Comments
 (0)