Skip to content

Commit 1133331

Browse files
committed
Fix restart kernel tests
1 parent 93ed1b1 commit 1133331

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

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

+47-19
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,16 +579,25 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
578579

579580
// Confirm message is displayed.
580581
installerSpy = sinon.spy(installer, 'install');
581-
const promptToInstall = await clickInstallFromIPyKernelPrompt();
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+
582596
await Promise.all([
583597
commandManager.executeCommand(Commands.RestartKernel, {
584598
notebookEditor: { notebookUri: nbFile }
585599
}),
586-
waitForCondition(
587-
async () => promptToInstall.displayed.then(() => true),
588-
delayForUITest,
589-
'Prompt not displayed'
590-
),
600+
waitForCondition(async () => installedIPyKernel, delayForUITest, 'Prompt not displayed'),
591601
waitForIPyKernelToGetInstalled()
592602
]);
593603
});
@@ -607,19 +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-
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');
613639
await Promise.all([
614-
commandManager.executeCommand(Commands.RestartKernel, {
615-
notebookEditor: { notebookUri: nbFile }
616-
}),
617-
waitForCondition(
618-
async () => promptToInstall.displayed.then(() => true),
619-
delayForUITest,
620-
'Prompt not displayed'
621-
),
622-
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'),
623643
// Verify the new kernel associated with this notebook is different.
624644
waitForCondition(
625645
async () => {
@@ -755,6 +775,14 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
755775
disposables
756776
);
757777
}
778+
async function clickOKForRestartPrompt() {
779+
return hijackPrompt(
780+
'showInformationMessage',
781+
{ contains: DataScience.restartKernelMessage },
782+
{ result: DataScience.restartKernelMessageYes, clickImmediately: true },
783+
disposables
784+
);
785+
}
758786
async function clickInstallFromIPyKernelPrompt() {
759787
return hijackPrompt(
760788
'showInformationMessage',

0 commit comments

Comments
 (0)