Repository navigation
Fix stale cached match count in AbstractTextSearchResult #4453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vogella
merged 1 commit into
eclipse-platform:master
from
vogella:lv/flaky-textsearchresulttest
Oct 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...pse.search.tests/src/org/eclipse/search/tests/AbstractTextSearchResultMatchCountTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 vogella GmbH and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package org.eclipse.search.tests; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.eclipse.jface.resource.ImageDescriptor; | ||
|
|
||
| import org.eclipse.search.ui.ISearchQuery; | ||
| import org.eclipse.search.ui.text.AbstractTextSearchResult; | ||
| import org.eclipse.search.ui.text.IEditorMatchAdapter; | ||
| import org.eclipse.search.ui.text.IFileMatchAdapter; | ||
| import org.eclipse.search.ui.text.Match; | ||
|
|
||
| public class AbstractTextSearchResultMatchCountTest { | ||
|
|
||
| private static final class TestResult extends AbstractTextSearchResult { | ||
| @Override | ||
| public String getLabel() { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public String getTooltip() { | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public ImageDescriptor getImageDescriptor() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ISearchQuery getQuery() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public IEditorMatchAdapter getEditorMatchAdapter() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public IFileMatchAdapter getFileMatchAdapter() { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** Element whose next hashCode() call parks the calling thread until released. */ | ||
| private static final class BlockingElement { | ||
| final CountDownLatch entered = new CountDownLatch(1); | ||
| final CountDownLatch release = new CountDownLatch(1); | ||
| volatile boolean armed = true; | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| if (armed) { | ||
| armed = false; | ||
| entered.countDown(); | ||
| try { | ||
| release.await(10, TimeUnit.SECONDS); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| return 42; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testMatchCountIsNotStaleWhenReadWhileMatchIsAdded() throws Exception { | ||
| TestResult result = new TestResult(); | ||
| result.addMatch(new Match("element", 0, 5)); | ||
| result.addMatch(new Match("element", 10, 5)); | ||
|
|
||
| BlockingElement blocking = new BlockingElement(); | ||
| Thread adder = new Thread(() -> result.addMatch(new Match(blocking, 0, 5))); | ||
| adder.setDaemon(true); | ||
| adder.start(); | ||
| try { | ||
| assertTrue(blocking.entered.await(10, TimeUnit.SECONDS)); | ||
| // Count while the add is in flight, so the count gets cached before the match lands | ||
| assertEquals(2, result.getMatchCount()); | ||
| } finally { | ||
| blocking.release.countDown(); | ||
| adder.join(10_000); | ||
| } | ||
| assertFalse(adder.isAlive()); | ||
| assertEquals(3, result.getMatchCount()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.