Skip to content

Commit f22f75c

Browse files
vogellafedejeanne
authored andcommitted
Fix order-dependent and stale-data assertions in CompletionTest
The checkCompletionContent method had two issues: 1. Order-dependent assertions: After async computation finishes, proposals from different processors are merged via CompletableFuture.thenAccept(addAll), and the final ordering depends on thread scheduling. The test assumed a fixed order. 2. Stale virtual table data: The completion proposal Table uses SWT.VIRTUAL. When setProposals() calls clearAll(), items are marked as unmaterialized but Widget.data is NOT cleared. The SWT.SetData handler sets both text and data, but getData() does not trigger SetData -- only getText()/getImage() do. The wait condition only checked item 0's text (via isComputingInfoEntry), leaving item 1 with stale data from the previous render. Fixes: - Check both items' text in the wait condition to force virtual table materialization via SWT.SetData for both items - Make proposal assertions order-independent Fixes #3880
1 parent 357b87c commit f22f75c

File tree

1 file changed

+17
-9
lines changed
  • tests/org.eclipse.ui.genericeditor.tests/src/org/eclipse/ui/genericeditor/tests

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,25 @@ private void checkCompletionContent(final Table completionProposalList) {
207207
completionProposalList.setSelection(initialProposalItem);
208208

209209
LongRunningBarContentAssistProcessor.finish();
210+
// Check both items' text (not just item 0) to force the virtual SWT Table
211+
// to materialize both items via SWT.SetData. Table.clearAll() marks items
212+
// as unmaterialized but does not clear Widget.data, so reading getData()
213+
// without prior getText() would return stale data from the previous render.
210214
waitForProposalRelatedCondition("Proposal list should contain two items", completionProposalList,
211-
() -> !isComputingInfoEntry(completionProposalList.getItem(0))
212-
&& completionProposalList.getItemCount() == 2,
215+
() -> completionProposalList.getItemCount() == 2
216+
&& !isComputingInfoEntry(completionProposalList.getItem(0))
217+
&& !isComputingInfoEntry(completionProposalList.getItem(1)),
213218
5_000);
214-
final TableItem firstCompletionProposalItem = completionProposalList.getItem(0);
215-
final TableItem secondCompletionProposalItem = completionProposalList.getItem(1);
216-
String firstCompletionProposalText = ((ICompletionProposal) firstCompletionProposalItem.getData()).getDisplayString();
217-
String secondCompletionProposalText = ((ICompletionProposal) secondCompletionProposalItem.getData()).getDisplayString();
218-
assertThat("Unexpected first proposal item", BAR_CONTENT_ASSIST_PROPOSAL, endsWith(firstCompletionProposalText));
219-
assertThat("Unexpected second proposal item", LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL,
220-
endsWith(secondCompletionProposalText));
219+
String firstText = ((ICompletionProposal) completionProposalList.getItem(0).getData()).getDisplayString();
220+
String secondText = ((ICompletionProposal) completionProposalList.getItem(1).getData()).getDisplayString();
221+
// Async completion processors may return results in any order, so verify
222+
// both proposals are present without assuming a specific order
223+
boolean barFirst = BAR_CONTENT_ASSIST_PROPOSAL.endsWith(firstText)
224+
&& LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL.endsWith(secondText);
225+
boolean longRunningFirst = LONG_RUNNING_BAR_CONTENT_ASSIST_PROPOSAL.endsWith(firstText)
226+
&& BAR_CONTENT_ASSIST_PROPOSAL.endsWith(secondText);
227+
assertTrue(barFirst || longRunningFirst,
228+
"Expected both bar and long-running proposals but got: [" + firstText + ", " + secondText + "]");
221229
String selectedProposalString = ((ICompletionProposal) completionProposalList.getSelection()[0].getData())
222230
.getDisplayString();
223231
assertEquals(initialProposalString, selectedProposalString,

0 commit comments

Comments
 (0)