-
Notifications
You must be signed in to change notification settings - Fork 414
Adding cancel execution command #1057
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
Conversation
76f33f9 to
2083ddf
Compare
| } | ||
|
|
||
| [Fact] | ||
| public async Task quit_command_cancels_all_deferred_commands_on_composite_kernel() |
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.
These aren't really just tests of the CompositeKernel. It might be useful to split them into a new test class and move toward a more vertical test organization.
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.
moved to QuiCommandTests class
| { | ||
| await Task.Delay(100); | ||
| await kernel.SendAsync(cancelCommand); | ||
| })).Wait(); |
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.
Make sure to enforce a timeout here.
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.
ok
| [Theory] | ||
| [InlineData(Language.CSharp)] | ||
| [InlineData(Language.FSharp)] | ||
| public async Task cancel_command_cancels_all_deferred_commands(Language language) |
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 looks like a duplicate. Consolidating will help make it clearer what we're testing.
| { | ||
| public Cancel(string targetKernelName = null): base(targetKernelName) | ||
| { | ||
| Handler = (command, context) => Task.CompletedTask; |
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.
It's preferable to override InvokeAsync. We should at some point limit the settable Handler property to only those commands that vary behavior by kernel.
| ClearPendingCommands(); | ||
| kernel.CancelInflightCommands(); | ||
| kernel.ClearPendingCommands(); | ||
| break; |
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.
Do these two cases need to vary in terms of behavior?
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.
might not be the case
| case Cancel _: | ||
|
|
||
| CancelInflightCommands(); | ||
| ClearPendingCommands(); |
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.
Is "pending" different from "deferred"?
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.
pending includes all things in the trampoline queue and the deferred
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.
So it might be clearer to say ClearQueuedAndDeferredCommand since both of those are terms that already exist in the code.
| throw new NoSuitableKernelException(command); | ||
| } | ||
|
|
||
| switch (command) |
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.
Rather than duplicating all of this, why not move it to the base and put the actual cancellation logic into a virtual method?
| { | ||
| private static readonly CompositeDisposable DisposeOnQuit = new(); | ||
|
|
||
| public static void RegisterForDisposalOnQuit(IDisposable disposable) |
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.
Why have potentially different disposal semantics than Kernel.Dispose? This looks like something that doesn't belong in the library. It should probably just be a host concern.
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.
we can have the host to register the OnQuit handler, and throw if it is not set
|
|
||
| public Quit(Action onQuit, string targetKernelName = null) : base(targetKernelName) | ||
| { | ||
| if (onQuit == null) |
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.
| if (onQuit == null) | |
| if (onQuit is null) |
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.
changed
| _events.OnCompleted(); | ||
| IsComplete = true; | ||
| _events.OnCompleted(); | ||
| _cancellationTokenSource.Cancel(false); |
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.
It looks like this gets called twice when someone is calling Cancel.
8a2ce09 to
fba0b52
Compare
|
|
||
| namespace Microsoft.DotNet.Interactive.Tests | ||
| { | ||
| [Collection("Do not parallelize")] |
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.
Why should these not be parallelizable? That sounds like a smell.
5289339 to
e3aa6bd
Compare
remove unused methods
deferred command that match the kernel used during scheduling of a command are executed deferred command order is preserved and parent kernel deferred commands are executed when scheduling commands on child kernel do not produce diagnostic events when there are none use callable command
ab93a75 to
314e740
Compare
d05b3d6 to
88cc568
Compare
Add tests for quit command