Skip to content

Commit e8f3ae0

Browse files
jonahgrahamSarikaSinha
authored andcommitted
Bug 576999: Wait for selectFrame to complete before resuming test
Doing a select frame causes (after some delay) a selectAndReveal on the editor for the frame's location. Make sure this selectAndReveal is complete before continuing the test. Prior to this patch, sometimes the frame's selectAndReveal ran after the key one in the test and the wrong thing would be selected in the editor for the test. triggerWinGerrit Change-Id: I7fbf951886ff157baa0b30fe5e3c73fa2aae0368 Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.debug/+/191738 Tested-by: JDT Bot <[email protected]> Tested-by: Releng Bot <[email protected]> Reviewed-by: Jonah Graham <[email protected]> Reviewed-by: Sarika Sinha <[email protected]>
1 parent 9fbdbbf commit e8f3ae0

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/DebugHoverTests.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.debug.tests.ui;
1515

16+
import static org.junit.Assert.assertNotEquals;
17+
1618
import java.util.LinkedHashMap;
1719
import java.util.Map;
1820
import java.util.Map.Entry;
@@ -1240,7 +1242,7 @@ public void testBug573547_insideLambda_onOuterScopeVariable_whileOnPreviousFrame
12401242
thread = launchToBreakpoint(typeName);
12411243
CompilationUnitEditor part = openEditorAndValidateStack(expectedMethod, frameNumber, file, thread);
12421244

1243-
selectFrame(thread.getStackFrames()[4]);
1245+
selectFrame(part, thread.getStackFrames()[4]);
12441246

12451247
JavaDebugHover hover = new JavaDebugHover();
12461248
hover.setEditor(part);
@@ -1453,16 +1455,33 @@ String selectAndReveal(CompilationUnitEditor editor, int line, IRegion region) t
14531455
return sync(() -> selection.getText());
14541456
}
14551457

1456-
private void selectFrame(IStackFrame frame) throws Exception {
1458+
private void selectFrame(CompilationUnitEditor editor, IStackFrame frame) throws Exception {
14571459
LaunchView debugView = sync(() -> (LaunchView) getActivePage().findView(IDebugUIConstants.ID_DEBUG_VIEW));
14581460
assertNotNull("expected Debug View to be open", debugView);
14591461

14601462
TreeSelection selection = sync(() -> (TreeSelection) debugView.getViewer().getSelection());
14611463
TreePath path = selection.getPaths()[0];
14621464
TreePath newPath = path.getParentPath().createChildPath(frame);
14631465
TreeSelection newSelection = new TreeSelection(newPath);
1464-
sync(() -> debugView.getViewer().setSelection(newSelection, true));
1465-
processUiEvents(100);
1466+
1467+
// frames uses 1 based line number, subtract 1 to line up with editor line numbers
1468+
int targetLineNumber = frame.getLineNumber() - 1;
1469+
int initialLineNumber = sync(() -> ((ITextSelection) editor.getSelectionProvider().getSelection()).getStartLine());
1470+
assertNotEquals("selectFrame cannot detect when it has"
1471+
+ "completed because selecting frame doesn't change the line number.", initialLineNumber, targetLineNumber);
1472+
final int timeoutms = 1000;
1473+
int selectedLineNumer = sync(() -> {
1474+
int lineNumber;
1475+
long endtime = System.currentTimeMillis() + timeoutms;
1476+
debugView.getViewer().setSelection(newSelection, true);
1477+
do {
1478+
TestUtil.runEventLoop();
1479+
lineNumber = ((ITextSelection) editor.getSelectionProvider().getSelection()).getStartLine();
1480+
} while (lineNumber != targetLineNumber && System.currentTimeMillis() < endtime);
1481+
return lineNumber;
1482+
});
1483+
assertEquals("After waiting " + timeoutms
1484+
+ "ms the editor selection was not moved to the expected line", targetLineNumber, selectedLineNumer);
14661485
}
14671486

14681487
@Override

0 commit comments

Comments
 (0)