-
Notifications
You must be signed in to change notification settings - Fork 350
Fix kernel picker UI stuck in loading state when third-party extensions throw CancellationError #16952
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
Closed
Closed
Fix kernel picker UI stuck in loading state when third-party extensions throw CancellationError #16952
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7aec45
Initial plan
Copilot 79fbf67
Implement fix for CancellationError handling in kernel picker
Copilot 8df24bd
Add comprehensive unit test for CancellationError handling fix
Copilot d99716c
Fix CancellationError handling by ensuring UI busy state is reset in …
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.unit.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { assert } from 'chai'; | ||
| import { anything, instance, mock, when } from 'ts-mockito'; | ||
| import { CancellationError, CancellationTokenSource, NotebookDocument } from 'vscode'; | ||
| import { IKernelFinder } from '../../../kernels/types'; | ||
| import { IJupyterServerUriStorage, IJupyterServerProviderRegistry } from '../../../kernels/jupyter/types'; | ||
| import { CodespacesJupyterServerSelector } from '../../../codespaces/codeSpacesServerSelector'; | ||
| import { JupyterConnection } from '../../../kernels/jupyter/connection/jupyterConnection'; | ||
| import { IConnectionDisplayDataProvider } from '../types'; | ||
| import { IRemoteKernelFinderController } from '../../../kernels/jupyter/finder/types'; | ||
| import { RemoteNotebookKernelSourceSelector } from './remoteNotebookKernelSourceSelector'; | ||
| import { JupyterServerCollection, JupyterServerCommand, JupyterServerCommandProvider } from '../../../api'; | ||
| import { InputFlowAction } from '../../../platform/common/utils/multiStepInput'; | ||
|
|
||
| suite('Remote Notebook Kernel Source Selector', () => { | ||
| let selector: RemoteNotebookKernelSourceSelector; | ||
| let kernelFinder: IKernelFinder; | ||
| let serverUriStorage: IJupyterServerUriStorage; | ||
| let serverSelector: CodespacesJupyterServerSelector; | ||
| let jupyterConnection: JupyterConnection; | ||
| let displayDataProvider: IConnectionDisplayDataProvider; | ||
| let kernelFinderController: IRemoteKernelFinderController; | ||
| let jupyterServerRegistry: IJupyterServerProviderRegistry; | ||
| let notebook: NotebookDocument; | ||
| let cancellationTokenSource: CancellationTokenSource; | ||
|
|
||
| setup(() => { | ||
| kernelFinder = mock<IKernelFinder>(); | ||
| serverUriStorage = mock<IJupyterServerUriStorage>(); | ||
| serverSelector = mock(CodespacesJupyterServerSelector); | ||
| jupyterConnection = mock(JupyterConnection); | ||
| displayDataProvider = mock<IConnectionDisplayDataProvider>(); | ||
| kernelFinderController = mock<IRemoteKernelFinderController>(); | ||
| jupyterServerRegistry = mock<IJupyterServerProviderRegistry>(); | ||
| notebook = mock<NotebookDocument>(); | ||
| cancellationTokenSource = new CancellationTokenSource(); | ||
|
|
||
| when(kernelFinder.registered).thenReturn([]); | ||
| when(serverUriStorage.all).thenReturn([]); | ||
| when(jupyterServerRegistry.jupyterCollections).thenReturn([]); | ||
|
|
||
| selector = new RemoteNotebookKernelSourceSelector( | ||
| instance(kernelFinder), | ||
| instance(serverUriStorage), | ||
| instance(serverSelector), | ||
| instance(jupyterConnection), | ||
| instance(displayDataProvider), | ||
| instance(kernelFinderController), | ||
| instance(jupyterServerRegistry) | ||
| ); | ||
| }); | ||
|
|
||
| teardown(() => { | ||
| cancellationTokenSource.dispose(); | ||
| }); | ||
|
|
||
| test('should handle CancellationError from handleCommand properly', async () => { | ||
| // Arrange | ||
| const mockCommandProvider = mock<JupyterServerCommandProvider>(); | ||
| const mockCollection = mock<JupyterServerCollection>(); | ||
| const mockCommand = mock<JupyterServerCommand>(); | ||
|
|
||
| when(mockCollection.extensionId).thenReturn('test-extension'); | ||
| when(mockCollection.id).thenReturn('test-id'); | ||
| when(mockCollection.commandProvider).thenReturn(instance(mockCommandProvider)); | ||
|
|
||
| when(mockCommandProvider.provideCommands(anything(), anything())).thenReturn([instance(mockCommand)]); | ||
| when(mockCommandProvider.handleCommand(anything(), anything())).thenReject(new CancellationError()); | ||
|
|
||
| when(notebook.notebookType).thenReturn('jupyter-notebook'); | ||
|
|
||
| // This test simulates what happens when a third-party extension's handleCommand throws CancellationError | ||
| // The expected behavior is that the UI should dismiss (CancellationError should propagate) | ||
| try { | ||
| await selector.selectRemoteKernel(instance(notebook), instance(mockCollection)); | ||
| assert.fail('Expected CancellationError to be thrown'); | ||
| } catch (error) { | ||
| assert.instanceOf(error, CancellationError, 'Should propagate CancellationError to dismiss UI'); | ||
| } | ||
| }); | ||
|
|
||
| test('should handle InputFlowAction.back from handleCommand by going back', async () => { | ||
| // Arrange | ||
| const mockCommandProvider = mock<JupyterServerCommandProvider>(); | ||
| const mockCollection = mock<JupyterServerCollection>(); | ||
| const mockCommand = mock<JupyterServerCommand>(); | ||
|
|
||
| when(mockCollection.extensionId).thenReturn('test-extension'); | ||
| when(mockCollection.id).thenReturn('test-id'); | ||
| when(mockCollection.commandProvider).thenReturn(instance(mockCommandProvider)); | ||
|
|
||
| when(mockCommandProvider.provideCommands(anything(), anything())).thenReturn([instance(mockCommand)]); | ||
| when(mockCommandProvider.handleCommand(anything(), anything())).thenResolve(undefined); // Returns undefined/null | ||
|
|
||
| when(notebook.notebookType).thenReturn('jupyter-notebook'); | ||
|
|
||
| // This test simulates what happens when a third-party extension's handleCommand returns undefined/null | ||
| // The expected behavior is that it should go back to the previous UI | ||
| try { | ||
| await selector.selectRemoteKernel(instance(notebook), instance(mockCollection)); | ||
| assert.fail('Expected InputFlowAction.back to be thrown'); | ||
| } catch (error) { | ||
| // This should either return undefined or throw InputFlowAction.back | ||
| assert.isTrue( | ||
| error === InputFlowAction.back || error instanceof CancellationError, | ||
| 'Should handle undefined return by going back or cancelling' | ||
| ); | ||
| } | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.