Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for resuming remote kernel execs #14255

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@
"VSC_JUPYTER_FORCE_LOGGING": "1",
"VSC_JUPYTER_CI_TEST_GREP": "", // Leave as `VSCode Notebook` to run only Notebook tests.
"VSC_JUPYTER_CI_TEST_INVERT_GREP": "", // Initialize this to invert the grep (exclude tests with value defined in grep).
"CI_PYTHON_PATH": "", // Update with path to real python interpereter used for testing.
"CI_PYTHON_PATH": "/Users/donjayamanne/crap/.venv/bin/python", // Update with path to real python interpereter used for testing.
"VSC_JUPYTER_CI_RUN_NON_PYTHON_NB_TEST": "", // Initialize this to run tests again Julia & other kernels.
"VSC_JUPYTER_WEBVIEW_TEST_MIDDLEWARE": "true", // Initialize to create the webview test middleware
"VSC_JUPYTER_LOAD_EXPERIMENTS_FROM_FILE": "true",
// "TF_BUILD": "", // Set to anything to force full logging
"TEST_FILES_SUFFIX": "*.vscode.test,*.vscode.common.test",
"VSC_JUPYTER_REMOTE_NATIVE_TEST": "false", // Change to `true` to run the Native Notebook tests with remote jupyter connections.
"VSC_JUPYTER_REMOTE_NATIVE_TEST": "true", // Change to `true` to run the Native Notebook tests with remote jupyter connections.
"VSC_JUPYTER_NON_RAW_NATIVE_TEST": "false", // Change to `true` to run the Native Notebook tests with non-raw kernels (i.e. local jupyter server).
"XVSC_JUPYTER_INSTRUMENT_CODE_FOR_COVERAGE": "1",
"XVSC_JUPYTER_INSTRUMENT_CODE_FOR_COVERAGE_HTML": "1", //Enable to get full coverage repor (in coverage folder).
Expand All @@ -242,7 +242,7 @@
},
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
"preLaunchTask": "Compile",
// "preLaunchTask": "Compile",
"skipFiles": ["<node_internals>/**"],
"presentation": {
"group": "2_tests",
Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"jupyter.generateSVGPlots": false,
// See https://github.com/microsoft/vscode-jupyter/issues/10258
"jupyter.forceIPyKernelDebugger": false,
"python.defaultInterpreterPath": "python",
"python.defaultInterpreterPath": "/Users/donjayamanne/crap/.venv/bin/python",
"task.problemMatchers.neverPrompt": {
"shell": true,
"npm": true
Expand Down
67 changes: 66 additions & 1 deletion src/test/datascience/notebook/remote.vscode.common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ import {
NotebookEdit,
NotebookEditor,
NotebookRange,
Uri,
window,
workspace,
WorkspaceEdit
} from 'vscode';
import { traceInfo } from '../../../platform/logging';
import { IDisposable } from '../../../platform/common/types';
import { captureScreenShot, startJupyterServer, suiteMandatory, testMandatory, waitForCondition } from '../../common';
import { initialize } from '../../initialize';
import { closeActiveWindows, initialize } from '../../initialize';
import {
closeNotebooks,
closeNotebooksAndCleanUpAfterTests,
createEmptyPythonNotebook,
defaultNotebookTestTimeout,
prewarmNotebooks,
runCell,
saveActiveNotebook,
selectDefaultController,
waitForExecutionCompletedSuccessfully,
waitForTextOutput
} from '../notebook/helper';
import { IS_REMOTE_NATIVE_TEST } from '../../constants';
import { noop } from '../../../platform/common/utils/misc';
import { sleep } from '../../core';

suiteMandatory('Remote Tests', function () {
const disposables: IDisposable[] = [];
Expand Down Expand Up @@ -80,4 +86,63 @@ suiteMandatory('Remote Tests', function () {
waitForTextOutput(cell, 'Hello World', 0, false)
]);
});
// eslint-disable-next-line no-only-tests/no-only-tests
test.only('Resume Cell Execution', async function () {
console.error('Step1');
await closeNotebooks([]);
console.error('Step2');
const nbFile = Uri.joinPath(workspace.workspaceFolders![0].uri, 'notebook', 'resumeExecution.ipynb');
fs
let editor = await workspace.openNotebookDocument(nbFile).then((nb) => window.showNotebookDocument(nb));
console.error('Step3');
const cell = editor.notebook.cellAt(0)!;
await selectDefaultController(editor);
console.error('Step4');
runCell(cell).then(noop, noop);
console.error('Step5');
await waitForTextOutput(cell, 'Started Execution', 0, false);
await waitForTextOutput(cell, 'Number:', undefined, false);
await sleep(2_000); // Wait for additional output
console.error('Step10');
console.error('Step6');
await saveActiveNotebook();
console.error('Step7');
await closeActiveWindows();
await sleep(5_000); // Some issues with the tests, possible not enough time for kernel to die
await closeActiveWindows();
console.error('Step8');
await sleep(5_000); // Some issues with the tests, possible not enough time for kernel to die
// Open the above notebook and see what the last output is.
const buffer = await workspace.fs.readFile(nbFile);
console.error('Step9');
const contents = JSON.parse(Buffer.from(buffer).toString().trim());
const lastCellOutputLines = contents.cells[0].outputs[0].text as string[];
const lastNumber = parseInt(
lastCellOutputLines[lastCellOutputLines.length - 1].trim().replace('Number:', '').trim(),
10
);
// await window.showErrorMessage(`Last Number is ${lastNumber}`).then(noop, noop);
console.error('Step11');

// Ok, now open the same document once again and execution should resume.
editor = await workspace.openNotebookDocument(nbFile).then((nb) => window.showNotebookDocument(nb));
console.error('Step12');
await waitForCondition(
() => {
const outputNumbers = Buffer.from(
editor.notebook.cellAt(0).outputs.slice(-1)[0].items.slice(-1)[0].data
)
.toString()
.trim()
.split(/\r?\n/)
.map((l) => l.trim())
.filter((l) => l.length);
console.error('Step13', outputNumbers);
const newLastNumber = parseInt(outputNumbers.slice(-1)[0].replace('Number:', '').trim(), 10);
return newLastNumber > lastNumber;
},
defaultNotebookTestTimeout,
'Execution did not resume'
);
});
});
48 changes: 48 additions & 0 deletions src/test/datascience/notebook/resumeExecution.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Started Execution\n",
"Number:0\n",
"Number:1\n",
"Number:2\n"
]
}
],
"source": [
"print(\"Started Execution\")\n",
"import os, time\n",
"\n",
"while True:\n",
" if os.path.exists(%FILE%):\n",
" break\n",
" time.sleep(1)\n",
"\n",
"print(\"Resuming Execution:1\")\n",
"time.sleep(1)\n",
"print(\"Resuming Execution:2\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python Kernel Spec",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}