Skip to content

Commit e22534a

Browse files
committed
Fix flaky AsyncContentAssistTest.testCompleteActivationChar
Replace Display.post() with control.notifyListeners() for reliable event delivery in headless CI environments. Display.post() sends native OS events that may not be processed, causing the content assist popup to never appear. Also fix race condition by capturing beforeShells before posting key events, process events after shell.open(), and increase findNewShell timeout from 1s to 5s for slower CI environments. Fixes #890
1 parent b24d027 commit e22534a

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AbstractContentAssistTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected static List<Shell> findNewShells(Collection<Shell> beforeShells) {
229229

230230
protected static Shell findNewShell(Collection<Shell> beforeShells) {
231231
List<Shell> afterShells= findNewShells(beforeShells);
232-
for (int attempt= 0; afterShells.size() != 1 && attempt < 10; attempt++) {
232+
for (int attempt= 0; afterShells.size() != 1 && attempt < 50; attempt++) {
233233
DisplayHelper.sleep(getDisplay(), 100);
234234
afterShells= findNewShells(beforeShells);
235235
}

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/AsyncContentAssistTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.junit.jupiter.api.Assertions.assertNotNull;
1818
import static org.junit.jupiter.api.Assertions.assertNull;
1919
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2120

2221
import java.util.Arrays;
2322
import java.util.Collection;
@@ -41,8 +40,6 @@
4140
import org.eclipse.core.runtime.IStatus;
4241
import org.eclipse.core.runtime.Platform;
4342

44-
import org.eclipse.jface.util.Util;
45-
4643
import org.eclipse.jface.text.Document;
4744
import org.eclipse.jface.text.IDocument;
4845
import org.eclipse.jface.text.contentassist.ContentAssistant;
@@ -134,7 +131,6 @@ protected boolean condition() {
134131

135132
@Test
136133
public void testCompleteActivationChar() {
137-
assumeFalse(Util.isWindows(), "test fails on Windows, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/890");
138134
shell.setLayout(new FillLayout());
139135
shell.setSize(500, 300);
140136
SourceViewer viewer= new SourceViewer(shell, null, SWT.NONE);
@@ -151,17 +147,20 @@ public void testCompleteActivationChar() {
151147
contentAssistant.install(viewer);
152148
shell.open();
153149
Display display= shell.getDisplay();
154-
Event keyEvent= new Event();
150+
DisplayHelper.runEventLoop(display, 0);
155151
Control control= viewer.getTextWidget();
152+
control.forceFocus();
153+
DisplayHelper.runEventLoop(display, 0);
154+
final Collection<Shell> beforeShells= AbstractContentAssistTest.getCurrentShells();
155+
// Use notifyListeners instead of Display.post() for reliable event delivery
156+
// Display.post() sends native OS events that may not be processed reliably
157+
// in headless CI environments
158+
Event keyEvent= new Event();
156159
keyEvent.widget= control;
157160
keyEvent.type= SWT.KeyDown;
158161
keyEvent.character= 'b';
159162
keyEvent.keyCode= 'b';
160-
control.getShell().forceActive();
161-
control.getDisplay().post(keyEvent);
162-
keyEvent.type= SWT.KeyUp;
163-
control.getDisplay().post(keyEvent);
164-
final Collection<Shell> beforeShells= AbstractContentAssistTest.getCurrentShells();
163+
control.notifyListeners(SWT.KeyDown, keyEvent);
165164
AbstractContentAssistTest.processEvents();
166165
Shell newShell= AbstractContentAssistTest.findNewShell(beforeShells);
167166
assertTrue(new DisplayHelper() {

0 commit comments

Comments
 (0)