Skip to content

Commit 2162c5b

Browse files
committed
Fix restart kernel tests
1 parent edc2329 commit 2162c5b

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

src/notebooks/notebookCommandListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export class NotebookCommandListener implements IDataScienceCommandListener {
7979
Commands.RestartKernel,
8080
(context?: { notebookEditor: { notebookUri: Uri } } | Uri) => {
8181
if (context && 'notebookEditor' in context) {
82-
this.restartKernel(context?.notebookEditor?.notebookUri).catch(noop);
82+
return this.restartKernel(context?.notebookEditor?.notebookUri).catch(noop);
8383
} else {
84-
this.restartKernel(context).catch(noop);
84+
return this.restartKernel(context).catch(noop);
8585
}
8686
}
8787
)

src/test/datascience/jupyter/kernels/installationPrompts.vscode.test.ts

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { isUri } from '../../../../platform/common/utils/misc';
6868
import { hasErrorOutput, translateCellErrorOutput } from '../../../../kernels/execution/helpers';
6969
import { BaseKernelError } from '../../../../kernels/errors/types';
7070
import { IControllerRegistration } from '../../../../notebooks/controllers/types';
71+
import { traceVerbose } from '../../../../platform/logging';
7172

7273
/* eslint-disable no-invalid-this, , , @typescript-eslint/no-explicit-any */
7374
suite('Install IPyKernel (install) @kernelInstall', function () {
@@ -562,7 +563,7 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
562563
await openNotebookAndInstallIpyKernelWhenRunningCell(venvNoKernelPath, venvNoRegPath, 'DoNotInstallIPyKernel');
563564
});
564565
// https://github.com/microsoft/vscode-jupyter/issues/12766
565-
test.skip('Should be prompted to re-install ipykernel when restarting a kernel from which ipykernel was uninstalled (VSCode Notebook)', async function () {
566+
test('Should be prompted to re-install ipykernel when restarting a kernel from which ipykernel was uninstalled (VSCode Notebook)', async function () {
566567
if (IS_REMOTE_NATIVE_TEST()) {
567568
return this.skip();
568569
}
@@ -578,18 +579,27 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
578579

579580
// Confirm message is displayed.
580581
installerSpy = sinon.spy(installer, 'install');
581-
const promptToInstall = await clickInstallFromIPyKernelPrompt();
582-
await commandManager.executeCommand(Commands.RestartKernel, {
583-
notebookEditor: { notebookUri: nbFile }
584-
}),
585-
await Promise.all([
586-
waitForCondition(
587-
async () => promptToInstall.displayed.then(() => true),
588-
delayForUITest,
589-
'Prompt not displayed'
590-
),
591-
waitForIPyKernelToGetInstalled()
592-
]);
582+
// Confirm message is displayed.
583+
let installedIPyKernel = false;
584+
585+
// First hookup the prompt for restarting the kernel;
586+
const restartPrompt = await clickOKForRestartPrompt();
587+
restartPrompt.displayed
588+
.then(async () => {
589+
restartPrompt.dispose();
590+
// Next hookup the prompt for re-install ipykernel.
591+
const selectionPrompt = await clickInstallFromIPyKernelPrompt();
592+
installedIPyKernel = await selectionPrompt.displayed;
593+
})
594+
.catch(noop);
595+
596+
await Promise.all([
597+
commandManager.executeCommand(Commands.RestartKernel, {
598+
notebookEditor: { notebookUri: nbFile }
599+
}),
600+
waitForCondition(async () => installedIPyKernel, delayForUITest, 'Prompt not displayed'),
601+
waitForIPyKernelToGetInstalled()
602+
]);
593603
});
594604
test('Ensure ipykernel install prompt is displayed and we can select another kernel after uninstalling IPyKernel from a live notebook and then restarting the kernel (VSCode Notebook)', async function () {
595605
if (IS_REMOTE_NATIVE_TEST()) {
@@ -607,20 +617,29 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
607617
assert.ok(startController);
608618

609619
// Confirm message is displayed.
610-
const promptToInstall = await selectKernelFromIPyKernelPrompt();
611-
const { kernelSelected } = hookupKernelSelected(promptToInstall, venvNoRegPath);
612-
await commands.executeCommand(Commands.RestartKernel, nbFile);
613-
620+
let promptToInstallDisplayed = false;
621+
let kernelSelected = false;
622+
623+
// First hookup the prompt for restarting the kernel;
624+
const restartPrompt = await clickOKForRestartPrompt();
625+
restartPrompt.displayed
626+
.then(async () => {
627+
restartPrompt.dispose();
628+
// Next hookup the prompt for re-install ipykernel.
629+
const selectionPrompt = await selectKernelFromIPyKernelPrompt();
630+
traceVerbose('Hooked prompt to change kernel');
631+
promptToInstallDisplayed = await selectionPrompt.displayed;
632+
traceVerbose('Displayed and handled prompt to change kernel', promptToInstallDisplayed);
633+
// Next hookup the prompt for selecting a kernel
634+
kernelSelected = await hookupKernelSelected(restartPrompt, venvNoRegPath).kernelSelected;
635+
traceVerbose('Hooked prompt to select a new kernel', kernelSelected);
636+
})
637+
.catch(noop);
638+
traceVerbose('Waiting For all');
614639
await Promise.all([
615-
await commandManager.executeCommand(Commands.RestartKernel, {
616-
notebookEditor: { notebookUri: nbFile }
617-
}),
618-
waitForCondition(
619-
async () => promptToInstall.displayed.then(() => true),
620-
delayForUITest,
621-
'Prompt not displayed'
622-
),
623-
waitForCondition(async () => kernelSelected, delayForUITest, 'New kernel not selected'),
640+
commandManager.executeCommand(Commands.RestartKernel, { notebookEditor: { notebookUri: nbFile } }),
641+
waitForCondition(() => promptToInstallDisplayed, delayForUITest, 'Prompt not displayed'),
642+
waitForCondition(() => kernelSelected, delayForUITest, 'New kernel not selected'),
624643
// Verify the new kernel associated with this notebook is different.
625644
waitForCondition(
626645
async () => {
@@ -756,6 +775,14 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
756775
disposables
757776
);
758777
}
778+
async function clickOKForRestartPrompt() {
779+
return hijackPrompt(
780+
'showInformationMessage',
781+
{ contains: DataScience.restartKernelMessage },
782+
{ result: DataScience.restartKernelMessageYes, clickImmediately: true },
783+
disposables
784+
);
785+
}
759786
async function clickInstallFromIPyKernelPrompt() {
760787
return hijackPrompt(
761788
'showInformationMessage',

0 commit comments

Comments
 (0)