Skip to content

Commit

Permalink
Fix restart kernel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Oct 27, 2023
1 parent 93ed1b1 commit 1133331
Showing 1 changed file with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { isUri } from '../../../../platform/common/utils/misc';
import { hasErrorOutput, translateCellErrorOutput } from '../../../../kernels/execution/helpers';
import { BaseKernelError } from '../../../../kernels/errors/types';
import { IControllerRegistration } from '../../../../notebooks/controllers/types';
import { traceVerbose } from '../../../../platform/logging';

/* eslint-disable no-invalid-this, , , @typescript-eslint/no-explicit-any */
suite('Install IPyKernel (install) @kernelInstall', function () {
Expand Down Expand Up @@ -562,7 +563,7 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
await openNotebookAndInstallIpyKernelWhenRunningCell(venvNoKernelPath, venvNoRegPath, 'DoNotInstallIPyKernel');
});
// https://github.com/microsoft/vscode-jupyter/issues/12766
test.skip('Should be prompted to re-install ipykernel when restarting a kernel from which ipykernel was uninstalled (VSCode Notebook)', async function () {
test('Should be prompted to re-install ipykernel when restarting a kernel from which ipykernel was uninstalled (VSCode Notebook)', async function () {
if (IS_REMOTE_NATIVE_TEST()) {
return this.skip();
}
Expand All @@ -578,16 +579,25 @@ suite('Install IPyKernel (install) @kernelInstall', function () {

// Confirm message is displayed.
installerSpy = sinon.spy(installer, 'install');
const promptToInstall = await clickInstallFromIPyKernelPrompt();
// Confirm message is displayed.
let installedIPyKernel = false;

// First hookup the prompt for restarting the kernel;
const restartPrompt = await clickOKForRestartPrompt();
restartPrompt.displayed
.then(async () => {
restartPrompt.dispose();
// Next hookup the prompt for re-install ipykernel.
const selectionPrompt = await clickInstallFromIPyKernelPrompt();
installedIPyKernel = await selectionPrompt.displayed;
})
.catch(noop);

await Promise.all([
commandManager.executeCommand(Commands.RestartKernel, {
notebookEditor: { notebookUri: nbFile }
}),
waitForCondition(
async () => promptToInstall.displayed.then(() => true),
delayForUITest,
'Prompt not displayed'
),
waitForCondition(async () => installedIPyKernel, delayForUITest, 'Prompt not displayed'),
waitForIPyKernelToGetInstalled()
]);
});
Expand All @@ -607,19 +617,29 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
assert.ok(startController);

// Confirm message is displayed.
const promptToInstall = await selectKernelFromIPyKernelPrompt();
const { kernelSelected } = hookupKernelSelected(promptToInstall, venvNoRegPath);

let promptToInstallDisplayed = false;
let kernelSelected = false;

// First hookup the prompt for restarting the kernel;
const restartPrompt = await clickOKForRestartPrompt();
restartPrompt.displayed
.then(async () => {
restartPrompt.dispose();
// Next hookup the prompt for re-install ipykernel.
const selectionPrompt = await selectKernelFromIPyKernelPrompt();
traceVerbose('Hooked prompt to change kernel');
promptToInstallDisplayed = await selectionPrompt.displayed;
traceVerbose('Displayed and handled prompt to change kernel', promptToInstallDisplayed);
// Next hookup the prompt for selecting a kernel
kernelSelected = await hookupKernelSelected(restartPrompt, venvNoRegPath).kernelSelected;
traceVerbose('Hooked prompt to select a new kernel', kernelSelected);
})
.catch(noop);
traceVerbose('Waiting For all');
await Promise.all([
commandManager.executeCommand(Commands.RestartKernel, {
notebookEditor: { notebookUri: nbFile }
}),
waitForCondition(
async () => promptToInstall.displayed.then(() => true),
delayForUITest,
'Prompt not displayed'
),
waitForCondition(async () => kernelSelected, delayForUITest, 'New kernel not selected'),
commandManager.executeCommand(Commands.RestartKernel, { notebookEditor: { notebookUri: nbFile } }),
waitForCondition(() => promptToInstallDisplayed, delayForUITest, 'Prompt not displayed'),
waitForCondition(() => kernelSelected, delayForUITest, 'New kernel not selected'),
// Verify the new kernel associated with this notebook is different.
waitForCondition(
async () => {
Expand Down Expand Up @@ -755,6 +775,14 @@ suite('Install IPyKernel (install) @kernelInstall', function () {
disposables
);
}
async function clickOKForRestartPrompt() {
return hijackPrompt(
'showInformationMessage',
{ contains: DataScience.restartKernelMessage },
{ result: DataScience.restartKernelMessageYes, clickImmediately: true },
disposables
);
}
async function clickInstallFromIPyKernelPrompt() {
return hijackPrompt(
'showInformationMessage',
Expand Down

0 comments on commit 1133331

Please sign in to comment.