public async Task TestDebugMagicCancel() { var engine = Init(); await AssertCompile(engine, SNIPPETS.SimpleDebugOperation, "SimpleDebugOperation"); var configSource = new ConfigurationSource(skipLoading: true); var debugMagic = new DebugMagic(engine.SymbolsResolver, configSource, engine.ShellRouter, engine.ShellServer, null); // Start a debug session var channel = new MockChannel(); var cts = new CancellationTokenSource(); var debugTask = debugMagic.RunAsync("SimpleDebugOperation", channel, cts.Token); // Cancel the session cts.Cancel(); // Ensure that the task throws an exception Assert.ThrowsException <AggregateException>(() => debugTask.Wait()); // Ensure that expected messages were sent Assert.AreEqual("iqsharp_debug_sessionstart", channel.iopubMessages[0].Header.MessageType); Assert.AreEqual("iqsharp_debug_sessionend", channel.iopubMessages[1].Header.MessageType); Assert.IsTrue(channel.msgs[0].Contains("Starting debug session")); Assert.IsTrue(channel.msgs[1].Contains("Finished debug session")); }
public async Task TestDebugMagic() { var engine = Init(); await AssertCompile(engine, SNIPPETS.SimpleDebugOperation, "SimpleDebugOperation"); var configSource = new ConfigurationSource(skipLoading: true); var debugMagic = new DebugMagic(engine.SymbolsResolver, configSource, engine.ShellRouter, engine.ShellServer, null); // Start a debug session var channel = new MockChannel(); var cts = new CancellationTokenSource(); var debugTask = debugMagic.RunAsync("SimpleDebugOperation", channel, cts.Token); // Retrieve the debug session ID var message = channel.iopubMessages[0]; Assert.IsNotNull(message); Assert.AreEqual("iqsharp_debug_sessionstart", message.Header.MessageType); var content = message.Content as DebugSessionContent; Assert.IsNotNull(content); var debugSessionId = content.DebugSession; // Send several iqsharp_debug_advance messages var debugAdvanceMessage = new Message { Header = new MessageHeader { MessageType = "iqsharp_debug_advance" }, Content = new UnknownContent { Data = new Dictionary <string, object> { ["debug_session"] = debugSessionId } } }; foreach (int _ in Enumerable.Range(0, 1000)) { Thread.Sleep(millisecondsTimeout: 10); if (debugTask.IsCompleted) { break; } await debugMagic.HandleAdvanceMessage(debugAdvanceMessage); } // Verify that the command completes successfully Assert.IsTrue(debugTask.IsCompleted); Assert.AreEqual(System.Threading.Tasks.TaskStatus.RanToCompletion, debugTask.Status); // Ensure that expected messages were sent Assert.AreEqual("iqsharp_debug_sessionstart", channel.iopubMessages[0].Header.MessageType); Assert.AreEqual("iqsharp_debug_opstart", channel.iopubMessages[1].Header.MessageType); Assert.AreEqual("iqsharp_debug_sessionend", channel.iopubMessages.Last().Header.MessageType); Assert.IsTrue(channel.msgs[0].Contains("Starting debug session")); Assert.IsTrue(channel.msgs[1].Contains("Finished debug session")); // Verify debug status content var debugStatusContent = channel.iopubMessages[1].Content as DebugStatusContent; Assert.IsNotNull(debugStatusContent.State); Assert.AreEqual(debugSessionId, debugStatusContent.DebugSession); }