|
35 | 35 | import org.eclipse.core.runtime.IContributor; |
36 | 36 | import org.eclipse.core.runtime.IExtensionRegistry; |
37 | 37 | import org.eclipse.core.runtime.Platform; |
| 38 | +import org.eclipse.core.runtime.content.IContentType; |
| 39 | +import org.eclipse.core.runtime.content.IContentTypeManager; |
38 | 40 |
|
39 | 41 | import org.eclipse.core.resources.IFile; |
40 | 42 | import org.eclipse.core.resources.IFolder; |
@@ -601,12 +603,31 @@ private void testBinaryContentTypeWithDescriber(TestResultCollector collector) t |
601 | 603 | .forEach(extension -> registry.removeExtension(extension, masterToken)); |
602 | 604 | }) { |
603 | 605 |
|
| 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 | + |
604 | 620 | // Use unique folder name to avoid conflicts with other tests running in parallel |
605 | 621 | String uniqueFolderName= "binaryContentTypeTest-" + java.util.UUID.randomUUID().toString(); |
606 | 622 | IFolder folder= ResourceHelper.createFolder(fProject.getFolder(uniqueFolderName)); |
607 | 623 | IFile textfile= ResourceHelper.createFile(folder, "textfile", "text hello"); |
608 | 624 | IFile binaryfile= ResourceHelper.createFile(folder, "binaryfile", "binary hello"); |
609 | 625 |
|
| 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 | + |
610 | 631 | Pattern searchPattern= PatternConstructor.createPattern("hello", true, false); |
611 | 632 |
|
612 | 633 | // Search only in the unique folder to avoid interference from other tests |
|
0 commit comments