Skip to content

Commit 0825899

Browse files
committed
Fixes
1 parent ae048d6 commit 0825899

File tree

2 files changed

+79
-20
lines changed

2 files changed

+79
-20
lines changed

src/test/datascience/notebook/helper.ts

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ import {
7979
defaultNotebookFormat,
8080
isWebExtension
8181
} from '../../../platform/common/constants';
82-
import { dispose } from '../../../platform/common/utils/lifecycle';
82+
import { dispose, type DisposableStore } from '../../../platform/common/utils/lifecycle';
8383
import { getDisplayPath } from '../../../platform/common/platform/fs-paths';
8484
import { IFileSystem, IPlatformService } from '../../../platform/common/platform/types';
8585
import { GLOBAL_MEMENTO, IDisposable, IMemento } from '../../../platform/common/types';
86-
import { createDeferred, sleep } from '../../../platform/common/utils/async';
86+
import { createDeferred, raceTimeoutError, sleep } from '../../../platform/common/utils/async';
8787
import { DataScience } from '../../../platform/common/utils/localize';
8888
import { isWeb } from '../../../platform/common/utils/misc';
8989
import { openAndShowNotebook } from '../../../platform/common/utils/notebooks';
@@ -970,6 +970,40 @@ export async function waitForExecutionCompletedSuccessfully(
970970
await sleep(100);
971971
}
972972

973+
export async function waitForExecutionCompletedSuccessfullyV2(
974+
cell: NotebookCell,
975+
disposables: IDisposable[] | DisposableStore
976+
) {
977+
const checkCompletedSuccessfully = () => {
978+
return cell.executionSummary?.success &&
979+
cell.executionSummary.executionOrder &&
980+
cell.executionSummary.timing?.endTime
981+
? true
982+
: false;
983+
};
984+
if (checkCompletedSuccessfully()) {
985+
return;
986+
}
987+
await new Promise((resolve) => {
988+
const disposable = workspace.onDidChangeNotebookDocument((e) => {
989+
if (e.notebook !== cell.notebook) {
990+
return;
991+
}
992+
e.cellChanges.forEach(() => {
993+
if (checkCompletedSuccessfully()) {
994+
disposable.dispose();
995+
resolve;
996+
}
997+
});
998+
});
999+
if (Array.isArray(disposables)) {
1000+
disposables.push(disposable);
1001+
} else {
1002+
disposables.add(disposable);
1003+
}
1004+
});
1005+
}
1006+
9731007
export async function waitForCompletions(
9741008
completionProvider: CompletionItemProvider,
9751009
cell: NotebookCell,
@@ -1208,6 +1242,38 @@ export async function waitForTextOutput(
12081242
.join(',\n')}`
12091243
);
12101244
}
1245+
export async function waitForTextOutputV2(
1246+
cell: NotebookCell,
1247+
text: string,
1248+
index: number = 0,
1249+
isExactMatch = true,
1250+
disposables: IDisposable[] | DisposableStore
1251+
) {
1252+
try {
1253+
assertHasTextOutputInVSCode(cell, text, index, isExactMatch);
1254+
return;
1255+
} catch {
1256+
//
1257+
}
1258+
await new Promise<void>((resolve) => {
1259+
const disposable = workspace.onDidChangeNotebookDocument((e) => {
1260+
if (e.notebook !== cell.notebook) {
1261+
return;
1262+
}
1263+
try {
1264+
assertHasTextOutputInVSCode(cell, text, index, isExactMatch);
1265+
resolve();
1266+
} catch {
1267+
//
1268+
}
1269+
});
1270+
if (Array.isArray(disposables)) {
1271+
disposables.push(disposable);
1272+
} else {
1273+
disposables.add(disposable);
1274+
}
1275+
});
1276+
}
12111277
export function assertNotHasTextOutputInVSCode(cell: NotebookCell, text: string, index: number, isExactMatch = true) {
12121278
const cellOutputs = cell.outputs;
12131279
assert.ok(cellOutputs, 'No output');

src/test/smoke/datascience.smoke.test.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { closeActiveWindows, initialize, initializeTest } from '../initialize.no
1111
import { captureScreenShot } from '../common';
1212
import { getCachedEnvironments } from '../../platform/interpreter/helpers';
1313
import { PythonExtension, type EnvironmentPath } from '@vscode/python-extension';
14+
import { waitForExecutionCompletedSuccessfullyV2, waitForTextOutputV2 } from '../datascience/notebook/helper';
15+
import { DisposableStore } from '../../platform/common/utils/lifecycle';
1416

1517
type JupyterApi = {
1618
openNotebook(uri: vscode.Uri, env: EnvironmentPath): Promise<void>;
@@ -19,6 +21,7 @@ type JupyterApi = {
1921
const timeoutForCellToRun = 3 * 60 * 1_000;
2022
suite('Smoke Tests', function () {
2123
this.timeout(timeoutForCellToRun);
24+
const disposableStore = new DisposableStore();
2225
suiteSetup(async function () {
2326
this.timeout(timeoutForCellToRun);
2427
if (!IS_SMOKE_TEST()) {
@@ -33,6 +36,7 @@ suite('Smoke Tests', function () {
3336
});
3437
suiteTeardown(closeActiveWindows);
3538
teardown(async function () {
39+
disposableStore.clear();
3640
logger.info(`End Test ${this.currentTest?.title}`);
3741
if (this.currentTest?.isFailed()) {
3842
await captureScreenShot(this);
@@ -69,15 +73,15 @@ suite('Smoke Tests', function () {
6973
// }).timeout(timeoutForCellToRun);
7074

7175
test('Run Cell in Notebook', async function () {
72-
const cell = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, 'print("Hello World")', 'python');
7376
const jupyterExt = vscode.extensions.getExtension<JupyterApi>(JVSC_EXTENSION_ID_FOR_TESTS);
7477
if (!jupyterExt) {
7578
throw new Error('Jupyter extension not found');
7679
}
80+
const cellData = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, 'print("Hello World")', 'python');
7781
const [pythonEnv, { notebook }] = await Promise.all([
7882
PythonExtension.api().then((api) => api.environments.resolveEnvironment(PYTHON_PATH)),
7983
vscode.workspace
80-
.openNotebookDocument('jupyter-notebook', new vscode.NotebookData([cell]))
84+
.openNotebookDocument('jupyter-notebook', new vscode.NotebookData([cellData]))
8185
.then((notebook) => vscode.window.showNotebookDocument(notebook)),
8286
jupyterExt.activate()
8387
]);
@@ -87,22 +91,11 @@ suite('Smoke Tests', function () {
8791
}
8892
await jupyterExt.exports.openNotebook(notebook.uri, pythonEnv);
8993

90-
await vscode.commands.executeCommand<void>('notebook.execute');
91-
92-
await new Promise<void>((resolve) => {
93-
const disposable = vscode.workspace.onDidChangeNotebookDocument((e) => {
94-
e.cellChanges.forEach((change) => {
95-
if (
96-
change.outputs?.some((o) =>
97-
o.items.some((i) => Buffer.from(i.data).toString('utf-8').includes('Hello World'))
98-
)
99-
) {
100-
disposable.dispose();
101-
resolve();
102-
}
103-
});
104-
});
105-
});
94+
await Promise.all([
95+
vscode.commands.executeCommand<void>('notebook.execute'),
96+
waitForTextOutputV2(notebook.cellAt(0), 'Hello World', 0, false, disposableStore),
97+
waitForExecutionCompletedSuccessfullyV2(notebook.cellAt(0), disposableStore)
98+
]);
10699
}).timeout(timeoutForCellToRun);
107100

108101
test('Interactive window should always pick up current active interpreter', async function () {

0 commit comments

Comments
 (0)