-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Microsoft.DotNet.Interactive.Tests/KernelCommandSchedulerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.DotNet.Interactive.Commands; | ||
using Microsoft.DotNet.Interactive.Tests.Utility; | ||
using Pocket; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.DotNet.Interactive.Tests | ||
{ | ||
public class KernelCommandSchedulerTests | ||
{ | ||
private readonly CompositeDisposable _disposables = new(); | ||
|
||
public KernelCommandSchedulerTests(ITestOutputHelper output) | ||
{ | ||
DisposeAfterTest(output.SubscribeToPocketLogger()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
_disposables?.Dispose(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger<KernelCommandSchedulerTests>.Log.Error(exception: ex); | ||
} | ||
} | ||
|
||
private void DisposeAfterTest(IDisposable disposable) | ||
{ | ||
_disposables.Add(disposable); | ||
} | ||
|
||
private void DisposeAfterTest(Action action) | ||
{ | ||
_disposables.Add(action); | ||
} | ||
|
||
[Fact] | ||
public async Task command_execute_on_kernel_specified_at_scheduling_time() | ||
{ | ||
var commandsHandledOnKernel1 = new List<KernelCommand>(); | ||
var commandsHandledOnKernel2 = new List<KernelCommand>(); | ||
|
||
var scheduler = new KernelCommandScheduler(); | ||
|
||
var kernel1 = new FakeKernel("kernel1") | ||
{ | ||
Handle = (command, context) => | ||
{ | ||
commandsHandledOnKernel1.Add(command); | ||
return Task.CompletedTask; | ||
} | ||
}; | ||
var kernel2 = new FakeKernel("kernel2") | ||
{ | ||
Handle = (command, context) => | ||
{ | ||
commandsHandledOnKernel2.Add(command); | ||
return Task.CompletedTask; | ||
} | ||
}; | ||
|
||
var command1 = new SubmitCode("for kernel 1"); | ||
var command2 = new SubmitCode("for kernel 2"); | ||
|
||
await scheduler.Schedule(command1, kernel1); | ||
await scheduler.Schedule(command2, kernel2); | ||
|
||
commandsHandledOnKernel1.Should().ContainSingle().Which.Should().Be(command1); | ||
commandsHandledOnKernel2.Should().ContainSingle().Which.Should().Be(command2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters