-
Notifications
You must be signed in to change notification settings - Fork 294
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
Fixes to flaky Installer Prompt tests #9358
Conversation
Codecov Report
@@ Coverage Diff @@
## main #9358 +/- ##
=====================================
Coverage 74% 74%
=====================================
Files 219 219
Lines 10939 10939
Branches 1571 1571
=====================================
+ Hits 8115 8153 +38
+ Misses 2195 2147 -48
- Partials 629 639 +10
|
cecd7ef
to
02254fe
Compare
Still flaky, |
switch (context) { | ||
case 'start': | ||
return (k: IKernel) => k.start(); | ||
return (k: IKernel) => k.start(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep track of whether UI is to be displayed or not.
When we use auto start we need to go through his same code.
@@ -55,25 +55,33 @@ export abstract class ModuleInstaller implements IModuleInstaller { | |||
const environmentService = this.serviceContainer.get<IEnvironmentVariablesService>( | |||
IEnvironmentVariablesService | |||
); | |||
if (cancelTokenSource.token.isCancellationRequested) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll see these in a few places, while running the tests found that these were causing issues.
Basically we had stopped cell execution (either closing a document or interrupt), & these code paths would continue running.
// When the progress is canceled notify caller | ||
token.onCancellationRequested(() => { | ||
cancelTokenSource.cancel(); | ||
deferred.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another fix, if token was cancelled, we should stop the installation
@@ -117,6 +117,9 @@ abstract class BaseInstaller { | |||
if (!installer) { | |||
return InstallerResponse.Ignore; | |||
} | |||
if (cancelTokenSource.token.isCancellationRequested) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll see these in a few places, while running the tests found that these were causing issues.
Basically we had stopped cell execution (either closing a document or interrupt), & these code paths would continue running.
/** | ||
* Used for debugging purposes, ability to uniquely identify kernels. | ||
*/ | ||
public readonly id: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was very useful, found we were creating a few kernels, initially I thought they were the same after adding this, found that we were actually creating new instances
@@ -248,20 +263,23 @@ export class Kernel implements IKernel { | |||
const disposeImpl = async () => { | |||
traceInfo(`Dispose kernel ${(this.resourceUri || this.notebookDocument.uri).toString()}`); | |||
this.restarting = undefined; | |||
const promises: Promise<void>[] = []; | |||
promises.push(this.kernelExecution.cancel()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found that when shutting down a kernel, we didn't cancel the pending executions, all we did was dispose that object.
This is kinda debt
if (!options.disableUI) { | ||
this.startupUI.disableUI = false; | ||
} | ||
options.onDidChangeDisableUI(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was missing, if we have auto start, then we don't display, but when running cells, the errors are not displayed as we're using the stale state of hiding the UI.
if (!promise) { | ||
const cancelTokenSource = new CancellationTokenSource(); | ||
const disposable = token.onCancellationRequested(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug, basically we stop execution, but this part continues, as we created a whole new cancellation token and ignored the one that was passed into this.
doc: NotebookDocument, | ||
options: IDisplayOptions = new DisplayOptions(false) | ||
): Promise<IKernel> { | ||
let currentPromise = VSCodeNotebookController.connections.get(doc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the bugs that was fixed, its an easy to repro issue:
- Open a notebook, select a kernel A without ipykernel
- Run all cells
- In the prompt displayed select the option to change the kernel to B
- We still get error message indicating ipykernel isnt found in A
- Run all cells again, and we'll still get errors about ipykernel not in A
The problem was we had connectToKernel
function called from different places and they all had their own while loops, and thats what caused issues (causing multiple kernels to get created, one gets created and disposes the other, and even after we change the controller, the previous loop will treat the older controller as active and weird things happend).
Basically we were running connectToKernel
function and had multiple while loops (instead of one) = now we cache it per doc.
@@ -584,7 +658,7 @@ export class VSCodeNotebookController implements Disposable { | |||
isLocalConnection(this.kernelConnection) | |||
) { | |||
// Startup could fail due to missing dependencies or the like. | |||
void newKernel.start({ disableUI: true }); | |||
this.connectToKernel(document, new DisplayOptions(true)).catch(noop); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THis was another fix, here we start newKernel.start
our selves, but connectToKernel
function will do something else and those two would step on each others toes.
@@ -127,8 +128,14 @@ export class CellExecutionQueue implements Disposable { | |||
|
|||
let executionResult: NotebookCellRunState | undefined; | |||
try { | |||
await cellToExecute.start(kernelConnection); | |||
executionResult = await cellToExecute.result; | |||
if (cellToExecute.cell.notebook.isClosed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found while debugging the tests.
Basically we stopped some tests early (which was not right), while some cells were still getting executed.
This ensures we don't run cells after a document has been closed.
The logs showed cells with index -1 were running.
Fixes #9186