diff --git a/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.ts b/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.ts index 35cc0a69fa4..5229fe9e043 100644 --- a/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.ts +++ b/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.ts @@ -468,9 +468,6 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel lazyQuickPick.busy = true; } const ret = await this.selectRemoteServerFromRemoteKernelFinder(selectedSource, state, token); - if (lazyQuickPick) { - lazyQuickPick.busy = false; - } return ret; } catch (ex) { if (ex === InputFlowAction.back && !defaultSelection) { @@ -479,6 +476,9 @@ export class RemoteNotebookKernelSourceSelector implements IRemoteNotebookKernel throw ex; } } finally { + if (lazyQuickPick) { + lazyQuickPick.busy = false; + } taskNb.dispose(); } } diff --git a/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.unit.test.ts b/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.unit.test.ts new file mode 100644 index 00000000000..4aa943cf69b --- /dev/null +++ b/src/notebooks/controllers/kernelSource/remoteNotebookKernelSourceSelector.unit.test.ts @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { assert } from 'chai'; + +suite('Remote Notebook Kernel Source Selector - UI State Management', () => { + test('should demonstrate busy state pattern expectations', () => { + // This test documents the expected behavior for UI busy state management + // The fix ensures that lazyQuickPick.busy is reset in finally block + + let busyState = false; + const mockQuickPick = { + set busy(value: boolean) { + busyState = value; + }, + get busy() { + return busyState; + } + }; + + // Simulate the fixed pattern: busy state reset in finally block + const simulateOperation = async (shouldThrow: boolean) => { + try { + mockQuickPick.busy = true; + if (shouldThrow) { + throw new Error('Simulated error'); + } + return 'success'; + } finally { + mockQuickPick.busy = false; + } + }; + + // Test successful case + return simulateOperation(false) + .then(() => { + assert.isFalse(mockQuickPick.busy, 'Busy state should be reset after success'); + }) + .then(() => { + // Test error case + return simulateOperation(true).catch(() => { + assert.isFalse(mockQuickPick.busy, 'Busy state should be reset even after errors'); + }); + }); + }); +});