Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Sep 12, 2019
1 parent 39b16c6 commit 96eaf94
Show file tree
Hide file tree
Showing 28 changed files with 383 additions and 293 deletions.
42 changes: 28 additions & 14 deletions MLS.Agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public static X509Certificate2 ParseKey(string base64EncodedKey)
typeof(Shell).Assembly
};

private static void StartLogging(CompositeDisposable disposables, StartupOptions options)
private static IDisposable StartAppInsightsLogging(StartupOptions options)
{

var disposables = new CompositeDisposable();

if (options.Production)
{
var applicationVersion = VersionSensor.Version().AssemblyInformationalVersion;
Expand All @@ -66,6 +69,24 @@ private static void StartLogging(CompositeDisposable disposables, StartupOptions
}));
}

if (options.ApplicationInsightsKey != null)
{
var telemetryClient = new TelemetryClient(new TelemetryConfiguration(options.ApplicationInsightsKey))
{
InstrumentationKey = options.ApplicationInsightsKey
};
disposables.Add(telemetryClient.SubscribeToPocketLogger(_assembliesEmittingPocketLoggerLogs));
}

Log.Event("AgentStarting");

return disposables;
}

internal static IDisposable StartToolLogging(StartupOptions options)
{
var disposables = new CompositeDisposable();

if (options.LogPath != null)
{
var log = new SerilogLoggerConfiguration()
Expand Down Expand Up @@ -94,22 +115,16 @@ private static void StartLogging(CompositeDisposable disposables, StartupOptions
args.SetObserved();
};

if (options.ApplicationInsightsKey != null)
{
var telemetryClient = new TelemetryClient(new TelemetryConfiguration(options.ApplicationInsightsKey))
{
InstrumentationKey = options.ApplicationInsightsKey
};
disposables.Add(telemetryClient.SubscribeToPocketLogger(_assembliesEmittingPocketLoggerLogs));
}

Log.Event("AgentStarting");
return disposables;
}

public static IWebHost ConstructWebHost(StartupOptions options)
{
var disposables = new CompositeDisposable();
StartLogging(disposables, options);
var disposables = new CompositeDisposable
{
StartAppInsightsLogging(options),
StartToolLogging(options)
};

if (options.Key is null)
{
Expand All @@ -120,7 +135,6 @@ public static IWebHost ConstructWebHost(StartupOptions options)
Log.Trace("Received Key: {key}", options.Key);
}


var webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Path.GetDirectoryName(typeof(Program).Assembly.Location))
Expand Down
Empty file added MLS.Blazor/App.g.cs
Empty file.
Empty file added MLS.Blazor/Pages/Index.g.cs
Empty file.
Empty file added MLS.Blazor/Pages/_Imports.g.cs
Empty file.
Empty file added MLS.Blazor/_Imports.g.cs
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Threading.Tasks;
using Clockwise;
using FluentAssertions;
using FluentAssertions.Extensions;
using Microsoft.DotNet.Interactive.Jupyter.Protocol;
using Recipes;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -22,9 +24,12 @@ public async Task send_completeReply_on_CompleteRequest()
{
var scheduler = CreateScheduler();
var request = Message.Create(new CompleteRequest("System.Console.", 15), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));

await _kernelStatus.Idle();
var context = new JupyterRequestContext(_serverChannel, _ioPubChannel, request);

await scheduler.Schedule(context);

await context.Done().Timeout(5.Seconds());

_serverRecordingSocket.DecodedMessages
.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public async Task sends_ExecuteInput_when_ExecuteRequest_is_handled()
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("var a =12;"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should().Contain(message =>
Expand All @@ -40,9 +40,9 @@ public async Task sends_ExecuteReply_message_on_when_code_submission_is_handled(
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("var a =12;"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should().Contain(message =>
Expand All @@ -54,9 +54,9 @@ public async Task sends_ExecuteReply_with_error_message_on_when_code_submission_
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("asdes"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should()
Expand All @@ -74,9 +74,9 @@ public async Task sends_DisplayData_message_on_ValueProduced()
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("Console.WriteLine(2+2);"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should().Contain(message =>
Expand All @@ -92,9 +92,9 @@ public async Task sends_ExecuteReply_message_on_ReturnValueProduced()
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("2+2"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should().Contain(message =>
Expand All @@ -110,9 +110,9 @@ public async Task sends_ExecuteReply_message_when_submission_contains_only_a_dir
{
var scheduler = CreateScheduler();
var request = Message.Create(new ExecuteRequest("%%csharp"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.Should().Contain(message =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Clockwise;
using FluentAssertions;
using System.Linq;
Expand All @@ -23,9 +22,9 @@ public async Task sends_InterruptReply()
{
var scheduler = CreateScheduler();
var request = Message.Create(new InterruptRequest(), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));

await _kernelStatus.Idle();
await _kernel.Idle();

_serverRecordingSocket.DecodedMessages
.SingleOrDefault(message =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public async Task sends_isCompleteReply_with_complete_if_the_code_is_a_complete_
var scheduler = CreateScheduler();
var request = Message.Create(new IsCompleteRequest("var a = 12;"), null);

await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await _kernelStatus.Idle();
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));
await _kernel.Idle();

Logger.Log.Info("DecodedMessages: {messages}", _serverRecordingSocket.DecodedMessages);

Expand All @@ -47,8 +47,8 @@ public async Task sends_isCompleteReply_with_incomplete_and_indent_if_the_code_i
{
var scheduler = CreateScheduler();
var request = Message.Create(new IsCompleteRequest("var a = 12"), null);
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request, _kernelStatus));
await _kernelStatus.Idle();
await scheduler.Schedule(new JupyterRequestContext(_serverChannel, _ioPubChannel, request));
await _kernel.Idle();
_serverRecordingSocket.DecodedMessages.SingleOrDefault(message =>
message.Contains(MessageTypeValues.IsCompleteReply))
.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,36 @@ namespace Microsoft.DotNet.Interactive.Jupyter.Tests
public abstract class JupyterRequestHandlerTestBase<T> : IDisposable
where T : JupyterMessageContent
{
private readonly CompositeDisposable _disposables =new CompositeDisposable();
private readonly CompositeDisposable _disposables = new CompositeDisposable();
protected readonly MessageSender _ioPubChannel;
protected readonly MessageSender _serverChannel;
protected readonly RecordingSocket _serverRecordingSocket;
protected readonly RecordingSocket _ioRecordingSocket;
protected readonly KernelStatus _kernelStatus;
protected readonly IKernel _kernel;

protected JupyterRequestHandlerTestBase(ITestOutputHelper output)
{
_disposables.Add(output.SubscribeToPocketLogger());

_kernel = new CompositeKernel
{
new CSharpKernel()
}.UseDefaultMagicCommands();

_disposables.Add(_kernel.LogEventsToPocketLogger());

var signatureValidator = new SignatureValidator("key", "HMACSHA256");
_serverRecordingSocket = new RecordingSocket();
_serverChannel = new MessageSender(_serverRecordingSocket, signatureValidator);
_ioRecordingSocket = new RecordingSocket();
_ioPubChannel = new MessageSender(_ioRecordingSocket, signatureValidator);
_kernelStatus = new KernelStatus(
Header.Create(typeof(T), "test"),
_serverChannel);
}

public void Dispose() => _disposables.Dispose();

protected ICommandScheduler<JupyterRequestContext> CreateScheduler()
{
var handler = new JupyterRequestContextHandler(new CompositeKernel
{
new CSharpKernel()
}.UseDefaultMagicCommands());
var handler = new JupyterRequestContextHandler(_kernel);

return CommandScheduler.Create<JupyterRequestContext>(handler.Handle).Trace();
}
Expand Down
72 changes: 0 additions & 72 deletions Microsoft.DotNet.Interactive.Jupyter.Tests/KernelStatusTests.cs

This file was deleted.

Loading

0 comments on commit 96eaf94

Please sign in to comment.