Skip to content

Commit f7c555a

Browse files
committed
Make completion proposal calculation test time-independent #906 #907
The test cases for completion proposals in CompletionTest depend on specific timing behavior of a test proposal processor. On one hand, this is prone to errors if proper timing is not given on the test environment. On the other hand, the tests run unnecessarily long because of waiting long enough. This change replaces the fixed-time waiting of the LongRunningBarContentAssistProcessor with an explicit trigger that finalizes the content calculation as soon as some barrier is reached within the tests. Contributes to #906 and #907
1 parent 1621d6e commit f7c555a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/CompletionTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,21 @@ private void checkCompletionContent(final Table completionProposalList) {
170170
protected boolean condition() {
171171
return completionProposalList.getItemCount() == 2;
172172
}
173-
}.waitForCondition(completionProposalList.getDisplay(), 200));
173+
}.waitForCondition(completionProposalList.getDisplay(), 5000));
174174
assertTrue("Missing computing info entry", isComputingInfoEntry(completionProposalList.getItem(0)));
175175
TableItem completionProposalItem = completionProposalList.getItem(1);
176176
final ICompletionProposal selectedProposal = (ICompletionProposal)completionProposalItem.getData();
177177
assertTrue("Incorrect proposal content", BarContentAssistProcessor.PROPOSAL.endsWith(selectedProposal .getDisplayString()));
178178
completionProposalList.setSelection(completionProposalItem);
179+
180+
LongRunningBarContentAssistProcessor.finishComputation();
179181
// asynchronous
180182
new DisplayHelper() {
181183
@Override
182184
protected boolean condition() {
183185
return !isComputingInfoEntry(completionProposalList.getItem(0)) && completionProposalList.getItemCount() == 2;
184186
}
185-
}.waitForCondition(completionProposalList.getDisplay(), LongRunningBarContentAssistProcessor.DELAY + 200);
187+
}.waitForCondition(completionProposalList.getDisplay(), 5000);
186188
completionProposalItem = completionProposalList.getItem(0);
187189
assertTrue("Proposal content seems incorrect", BarContentAssistProcessor.PROPOSAL.endsWith(((ICompletionProposal)completionProposalItem.getData()).getDisplayString()));
188190
TableItem otherProposalItem = completionProposalList.getItem(1);
@@ -225,7 +227,7 @@ protected boolean condition() {
225227
emulatePressLeftArrowKey();
226228
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 200); //give time to process events
227229
long processingDuration = System.currentTimeMillis() - timestamp;
228-
assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.DELAY);
230+
assertTrue("UI Thread frozen for " + processingDuration + "ms", processingDuration < LongRunningBarContentAssistProcessor.TIMEOUT_MSEC);
229231
}
230232

231233
@Test

tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests/contributions/LongRunningBarContentAssistProcessor.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,38 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.genericeditor.tests.contributions;
1515

16+
import static org.junit.Assert.assertFalse;
17+
1618
import org.eclipse.jface.text.ITextViewer;
1719
import org.eclipse.jface.text.contentassist.ICompletionProposal;
1820

1921
public class LongRunningBarContentAssistProcessor extends BarContentAssistProcessor {
2022

2123
public static final String PROPOSAL = "bars are also good for soft drink cocktails.";
22-
public static final int DELAY = 2000;
23-
24+
public static final int TIMEOUT_MSEC = 10_000;
25+
private static boolean shouldComputationFinish = false;
26+
2427
public LongRunningBarContentAssistProcessor() {
2528
super(PROPOSAL);
2629
}
2730

2831
@Override
2932
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
3033
try {
31-
Thread.sleep(DELAY);
34+
long startExecutionTime = System.currentTimeMillis();
35+
while (!shouldComputationFinish && (System.currentTimeMillis() - startExecutionTime) < TIMEOUT_MSEC) {
36+
Thread.sleep(20);
37+
}
3238
} catch (InterruptedException e) {
33-
// TODO Auto-generated catch block
34-
e.printStackTrace();
39+
// Just finish on unexpected interrupt
3540
}
41+
shouldComputationFinish = false;
3642
return super.computeCompletionProposals(viewer, offset);
3743
}
44+
45+
public static void finishComputation() {
46+
assertFalse("Concurrent requests for finishing computation of long running content assist processor", shouldComputationFinish);
47+
shouldComputationFinish = true;
48+
}
49+
3850
}

0 commit comments

Comments
 (0)