Skip to content

Commit 7f27375

Browse files
committed
Arcane workaround to fix a flaky test
For an inexplicable reason, the first time the selection occurs, the value is incorrect. We often miss this error in our tests if the expectation is reached before the selection changed event fires. It seems that the _second_ time the selection changed event fires, the value is correct. This change ensures we wait for the second selection change. And we avoid running expectations until then.e
1 parent 01e1f13 commit 7f27375

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

extensions/ql-vscode/src/vscode-tests/no-workspace/query-history.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,29 @@ describe('query-history', () => {
402402
});
403403
});
404404

405-
it('should get the selection from the treeView when both selections are empty', async () => {
405+
it('should get the selection from the treeView when both selections are empty', async function() {
406+
this.timeout(999999999);
406407
queryHistoryManager = await createMockQueryHistory(allHistory);
407-
await queryHistoryManager.treeView.reveal(allHistory[1], { select: true });
408-
const selection = (queryHistoryManager as any).determineSelection(undefined, undefined);
409-
expect(selection).to.deep.eq({
410-
finalSingleItem: allHistory[1],
411-
finalMultiSelect: [allHistory[1]]
408+
const p = new Promise<void>(done => {
409+
queryHistoryManager!.treeView.onDidChangeSelection(s => {
410+
if (s.selection[0] !== allHistory[1]) {
411+
return;
412+
}
413+
const selection = (queryHistoryManager as any).determineSelection(undefined, undefined);
414+
expect(selection).to.deep.eq({
415+
finalSingleItem: allHistory[1],
416+
finalMultiSelect: [allHistory[1]]
417+
});
418+
done();
419+
});
412420
});
421+
422+
// I can't explain why, but the first time the onDidChangeSelection event fires, the selection is
423+
// not correct (it is inexplicably allHistory[2]). So we fire the event a second time to get the
424+
// correct selection.
425+
await queryHistoryManager.treeView.reveal(allHistory[0], { select: true });
426+
await queryHistoryManager.treeView.reveal(allHistory[1], { select: true });
427+
await p;
413428
});
414429

415430
it('should get the selection from the treeDataProvider when both selections and the treeView are empty', async () => {

0 commit comments

Comments
 (0)