Exemplo n.º 1
0
        public async Task it_can_cancel_execution(Language language)
        {
            var kernel = CreateKernel(language);

            var source = language switch
            {
                Language.FSharp => "System.Threading.Thread.Sleep(3000)\r\n2",
                Language.CSharp => "System.Threading.Thread.Sleep(3000);2"
            };

            var submitCodeCommand   = new SubmitCode(source);
            var codeSubmission      = kernel.SendAsync(submitCodeCommand);
            var interruptionCommand = new CancelCurrentCommand();
            await kernel.SendAsync(interruptionCommand);

            await codeSubmission;

            // verify cancel command
            KernelEvents
            .Single(e => e is CurrentCommandCancelled);

            // verify failure
            KernelEvents
            .OfType <CommandFailed>()
            .Should()
            .BeEquivalentTo(new CommandFailed(null, interruptionCommand, "Command cancelled"));

            // verify `2` isn't evaluated and returned
            KernelEvents
            .OfType <ReturnValueProduced>()
            .Should()
            .BeEmpty();
        }
Exemplo n.º 2
0
        public async Task it_can_cancel_execution(Language language)
        {
            var kernel = CreateKernel(language);

            var source = language switch
            {
                Language.FSharp => "System.Threading.Thread.Sleep(3000)\r\n2",
                Language.CSharp => "System.Threading.Thread.Sleep(3000);2",
                Language.PowerShell => "Start-Sleep -Seconds 3; 2"
            };

            var submitCodeCommand   = new SubmitCode(source);
            var codeSubmission      = kernel.SendAsync(submitCodeCommand);
            var interruptionCommand = new CancelCurrentCommand();
            await kernel.SendAsync(interruptionCommand);

            await codeSubmission;

            // verify cancel command
            KernelEvents
            .Should()
            .ContainSingle <CurrentCommandCancelled>();

            // verify failure
            KernelEvents
            .Should()
            .ContainSingle <CommandFailed>();

            // verify `2` isn't evaluated and returned
            KernelEvents
            .Should()
            .NotContain(e => e is DisplayEventBase);
        }
Exemplo n.º 3
0
        //[InlineData(Language.FSharp)]                     // Todo: FSI interrupt command_failed : cancelled command
        public async Task it_can_cancel_execution(Language language)
        {
            var kernel = CreateKernel(language);

            var source = language switch
            {
                Language.FSharp => "System.Threading.Thread.Sleep(3000)",
                Language.CSharp => "System.Threading.Thread.Sleep(3000);"
            };

            var submitCodeCommand   = new SubmitCode(source);
            var codeSubmission      = kernel.SendAsync(submitCodeCommand);
            var interruptionCommand = new CancelCurrentCommand();
            await kernel.SendAsync(interruptionCommand);

            await codeSubmission;

            KernelEvents
            .ValuesOnly()
            .Single(e => e is CurrentCommandCancelled);

            KernelEvents
            .ValuesOnly()
            .OfType <CommandFailed>()
            .Should()
            .BeEquivalentTo(new CommandFailed(null, interruptionCommand, "Command cancelled"));
        }
Exemplo n.º 4
0
        private async Task HandleCancelCurrentCommand(
            CancelCurrentCommand cancelCurrentCommand,
            KernelInvocationContext context)
        {
            var reply = new CurrentCommandCancelled(cancelCurrentCommand);

            lock (_cancellationSourceLock)
            {
                _cancellationSource.Cancel();
                _cancellationSource = new CancellationTokenSource();
            }

            context.Publish(reply);
        }
Exemplo n.º 5
0
        public async Task Handle(JupyterRequestContext context)
        {
            var interruptRequest = GetJupyterRequest(context);

            context.RequestHandlerStatus.SetAsBusy();

            var command = new CancelCurrentCommand();

            var openRequest = new InflightRequest(context, interruptRequest, 0);

            InFlightRequests[command] = openRequest;

            await Kernel.SendAsync(command);
        }
Exemplo n.º 6
0
        public async Task it_can_cancel_execution()
        {
            var kernel = CreateKernel();

            var submitCodeCommand   = new SubmitCode(@"System.Threading.Thread.Sleep(90000000);");
            var codeSubmission      = kernel.SendAsync(submitCodeCommand);
            var interruptionCommand = new CancelCurrentCommand();
            await kernel.SendAsync(interruptionCommand);

            await codeSubmission;

            KernelEvents
            .ValuesOnly()
            .Single(e => e is CurrentCommandCancelled);

            KernelEvents
            .ValuesOnly()
            .OfType <CommandFailed>()
            .Should()
            .BeEquivalentTo(new CommandFailed(null, interruptionCommand, "Command cancelled"));
        }
Exemplo n.º 7
0
        public async Task Handle(JupyterRequestContext context)
        {
            var command = new CancelCurrentCommand();

            await SendTheThingAndWaitForTheStuff(context, command);
        }
Exemplo n.º 8
0
        public async Task Handle(JupyterRequestContext context)
        {
            var command = new CancelCurrentCommand();

            await SendAsync(context, command);
        }