From 1352e9d43cc54775086a873950527a2be0e80c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 10 Jul 2026 09:14:47 +0300 Subject: [PATCH] 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> --- .../org/eclipse/search/tests/filesearch/SortingTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java b/tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java index 51fec22a403..dce8817fade 100644 --- a/tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java +++ b/tests/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/SortingTest.java @@ -52,8 +52,8 @@ public void testSorted() throws Exception { NewSearchUI.activateSearchResultView(); NewSearchUI.runQueryInForeground(null, fQuery1); AbstractTextSearchResult result= (AbstractTextSearchResult) fQuery1.getSearchResult(); - int originalMatchCount= result.getMatchCount(); - List allMatches= new ArrayList<>(originalMatchCount); + List allMatches= new ArrayList<>(result.getMatchCount()); + int originalMatchCount= 0; // first, collect all matches Object[] elements= result.getElements(); @@ -61,6 +61,7 @@ public void testSorted() throws Exception { int sizeBefore= allMatches.size(); Match[] matches = result.getMatches(element); Collections.addAll(allMatches, matches); + originalMatchCount += matches.length; int sizeAfter= allMatches.size(); assertEquals(sizeBefore + matches.length, sizeAfter, "Failed to add matches:" + Arrays.stream(matches).map(Match::toString).collect(Collectors.joining(System.lineSeparator()))); @@ -80,7 +81,7 @@ public void testSorted() throws Exception { assertEquals(sizeBefore + 1, sizeAfter, "Failed to add match:" + match); } - assertEquals(result.getMatchCount(), originalMatchCount, "Test that all matches have been added again"); + assertEquals(originalMatchCount, result.getMatchCount(), "Test that all matches have been added again"); // now check that they're ordered by position. for (Object element : elements) {