Skip to content
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

Adding cancel execution command #1057

Closed
wants to merge 44 commits into from

Conversation

colombod
Copy link
Member

Add tests for quit command

@runfoapp runfoapp bot mentioned this pull request Feb 11, 2021
@colombod colombod force-pushed the cancel_execution_command branch 3 times, most recently from 76f33f9 to 2083ddf Compare February 15, 2021 01:05
@@ -425,6 +426,189 @@ public async Task Deferred_commands_on_composite_kernel_are_execute_on_first_sub
typeof(CommandSucceeded));
}

[Fact]
public async Task quit_command_cancels_all_deferred_commands_on_composite_kernel()
Copy link
Contributor

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.

Copy link
Member Author

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();
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Member Author

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();
Copy link
Contributor

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"?

Copy link
Member Author

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

Copy link
Contributor

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.

@@ -213,6 +213,22 @@ protected override void SetHandlingKernel(KernelCommand command, KernelInvocatio
throw new NoSuitableKernelException(command);
}

switch (command)
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (onQuit == null)
if (onQuit is null)

Copy link
Member Author

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);
Copy link
Contributor

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.

@colombod colombod force-pushed the cancel_execution_command branch 5 times, most recently from 8a2ce09 to fba0b52 Compare February 17, 2021 20:18

namespace Microsoft.DotNet.Interactive.Tests
{
[Collection("Do not parallelize")]
Copy link
Contributor

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.

@colombod colombod force-pushed the cancel_execution_command branch 7 times, most recently from 5289339 to e3aa6bd Compare February 20, 2021 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants