Skip to content

Commit f66c97d

Browse files
akurtakovCopilot
andcommitted
Stabilize SortingTest match count
Why mismatch: getMatchCount() can observe a different concurrent state than getElements()/getMatches() (cached count vs traversal), so the old comparison could race on Windows. Fix: derive baseline count from the same collected match snapshot used for allMatches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4e93fb9 commit f66c97d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ public void testSorted() throws Exception {
5252
NewSearchUI.activateSearchResultView();
5353
NewSearchUI.runQueryInForeground(null, fQuery1);
5454
AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult();
55-
int originalMatchCount= result.getMatchCount();
56-
List<Match> allMatches= new ArrayList<>(originalMatchCount);
55+
List<Match> allMatches= new ArrayList<>(result.getMatchCount());
56+
int originalMatchCount= 0;
5757

5858
// first, collect all matches
5959
Object[] elements= result.getElements();
6060
for (Object element : elements) {
6161
int sizeBefore= allMatches.size();
6262
Match[] matches = result.getMatches(element);
6363
Collections.addAll(allMatches, matches);
64+
originalMatchCount += matches.length;
6465
int sizeAfter= allMatches.size();
6566
assertEquals(sizeBefore + matches.length, sizeAfter, "Failed to add matches:" +
6667
Arrays.stream(matches).map(Match::toString).collect(Collectors.joining(System.lineSeparator())));
@@ -80,7 +81,7 @@ public void testSorted() throws Exception {
8081
assertEquals(sizeBefore + 1, sizeAfter, "Failed to add match:" + match);
8182
}
8283

83-
assertEquals(result.getMatchCount(), originalMatchCount, "Test that all matches have been added again");
84+
assertEquals(originalMatchCount, result.getMatchCount(), "Test that all matches have been added again");
8485

8586
// now check that they're ordered by position.
8687
for (Object element : elements) {

0 commit comments

Comments
 (0)