Skip to content

Commit 7c0684c

Browse files
vogellaclaude
andcommitted
Fix flaky QuickAccessComputerTest by waiting for async search results
The test was failing intermittently because QuickSearchQuickAccessComputer performs asynchronous background searches with a 200ms timeout. On slower CI systems (particularly macOS), this timeout was insufficient, causing the test to fail when it checked for results before the search completed. This fix: - Saves the Display reference before closing the dialog to avoid NPE - Wraps the QuickAccessComputer result check in DisplayHelper.waitForCondition with a 5-second timeout, retrying if no results are found initially - Allows the background search job sufficient time to find matches The test now passes consistently across multiple runs. Fixes #3042 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 55574d8 commit 7c0684c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/org.eclipse.text.quicksearch.tests/src/org/eclipse/text/quicksearch/tests/QuickAccessComputerTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*******************************************************************************/
1010
package org.eclipse.text.quicksearch.tests;
1111

12-
import static org.junit.jupiter.api.Assertions.assertEquals;
1312
import static org.junit.jupiter.api.Assertions.assertTrue;
1413

1514
import java.io.IOException;
@@ -55,8 +54,16 @@ void testQuickAccessComputer() throws CoreException, IOException {
5554
dialog.setInitialPattern(request);
5655
dialog.setBlockOnOpen(false);
5756
dialog.open();
58-
assertTrue(DisplayHelper.waitForCondition(dialog.getShell().getDisplay(), 2000, () -> dialog.getResult().length > 0));
57+
var display = dialog.getShell().getDisplay();
58+
assertTrue(DisplayHelper.waitForCondition(display, 2000, () -> dialog.getResult().length > 0));
5959
dialog.close();
60-
assertEquals(1, new QuickSearchQuickAccessComputer().computeElements(request, new NullProgressMonitor()).length);
60+
61+
// Wait for the QuickAccessComputer to return results, as the search happens asynchronously.
62+
// Retry the search if it initially returns no results, allowing time for the background
63+
// search job to find matches. This addresses race conditions on slower CI systems.
64+
assertTrue(DisplayHelper.waitForCondition(display, 5000, () -> {
65+
QuickSearchQuickAccessComputer computer = new QuickSearchQuickAccessComputer();
66+
return computer.computeElements(request, new NullProgressMonitor()).length == 1;
67+
}), "Expected QuickAccessComputer to find exactly one result within timeout");
6168
}
6269
}

0 commit comments

Comments
 (0)