forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net] Dispose kernel after running dotnet interactive tests (microso…
…ft#3378) * dispose kernel after running test * add timeout
- Loading branch information
1 parent
a13e4db
commit 5c8f010
Showing
4 changed files
with
78 additions
and
70 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
131 changes: 66 additions & 65 deletions
131
dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveServiceTest.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 |
---|---|---|
@@ -1,82 +1,83 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// DotnetInteractiveServiceTest.cs | ||
|
||
//using FluentAssertions; | ||
//using Xunit; | ||
//using Xunit.Abstractions; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
//namespace AutoGen.DotnetInteractive.Tests; | ||
namespace AutoGen.DotnetInteractive.Tests; | ||
|
||
//public class DotnetInteractiveServiceTest : IDisposable | ||
//{ | ||
// private ITestOutputHelper _output; | ||
// private InteractiveService _interactiveService; | ||
// private string _workingDir; | ||
[Collection("Sequential")] | ||
public class DotnetInteractiveServiceTest : IDisposable | ||
{ | ||
private ITestOutputHelper _output; | ||
private InteractiveService _interactiveService; | ||
private string _workingDir; | ||
|
||
// public DotnetInteractiveServiceTest(ITestOutputHelper output) | ||
// { | ||
// _output = output; | ||
// _workingDir = Path.Combine(Path.GetTempPath(), "test", Path.GetRandomFileName()); | ||
// if (!Directory.Exists(_workingDir)) | ||
// { | ||
// Directory.CreateDirectory(_workingDir); | ||
// } | ||
public DotnetInteractiveServiceTest(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
_workingDir = Path.Combine(Path.GetTempPath(), "test", Path.GetRandomFileName()); | ||
if (!Directory.Exists(_workingDir)) | ||
{ | ||
Directory.CreateDirectory(_workingDir); | ||
} | ||
|
||
// _interactiveService = new InteractiveService(_workingDir); | ||
// _interactiveService.StartAsync(_workingDir, default).Wait(); | ||
// } | ||
_interactiveService = new InteractiveService(_workingDir); | ||
_interactiveService.StartAsync(_workingDir, default).Wait(); | ||
} | ||
|
||
// public void Dispose() | ||
// { | ||
// _interactiveService.Dispose(); | ||
// } | ||
public void Dispose() | ||
{ | ||
_interactiveService.Dispose(); | ||
} | ||
|
||
// [Fact] | ||
// public async Task ItRunCSharpCodeSnippetTestsAsync() | ||
// { | ||
// var cts = new CancellationTokenSource(); | ||
// var isRunning = await _interactiveService.StartAsync(_workingDir, cts.Token); | ||
[Fact] | ||
public async Task ItRunCSharpCodeSnippetTestsAsync() | ||
{ | ||
var cts = new CancellationTokenSource(); | ||
var isRunning = await _interactiveService.StartAsync(_workingDir, cts.Token); | ||
|
||
// isRunning.Should().BeTrue(); | ||
isRunning.Should().BeTrue(); | ||
|
||
// _interactiveService.IsRunning().Should().BeTrue(); | ||
_interactiveService.IsRunning().Should().BeTrue(); | ||
|
||
// // test code snippet | ||
// var hello_world = @" | ||
//Console.WriteLine(""hello world""); | ||
//"; | ||
// test code snippet | ||
var hello_world = @" | ||
Console.WriteLine(""hello world""); | ||
"; | ||
|
||
// await this.TestCSharpCodeSnippet(_interactiveService, hello_world, "hello world"); | ||
// await this.TestCSharpCodeSnippet( | ||
// _interactiveService, | ||
// code: @" | ||
//Console.WriteLine(""hello world"" | ||
//", | ||
// expectedOutput: "Error: (2,32): error CS1026: ) expected"); | ||
await this.TestCSharpCodeSnippet(_interactiveService, hello_world, "hello world"); | ||
await this.TestCSharpCodeSnippet( | ||
_interactiveService, | ||
code: @" | ||
Console.WriteLine(""hello world"" | ||
", | ||
expectedOutput: "Error: (2,32): error CS1026: ) expected"); | ||
|
||
// await this.TestCSharpCodeSnippet( | ||
// service: _interactiveService, | ||
// code: "throw new Exception();", | ||
// expectedOutput: "Error: System.Exception: Exception of type 'System.Exception' was thrown"); | ||
// } | ||
await this.TestCSharpCodeSnippet( | ||
service: _interactiveService, | ||
code: "throw new Exception();", | ||
expectedOutput: "Error: System.Exception: Exception of type 'System.Exception' was thrown"); | ||
} | ||
|
||
// [Fact] | ||
// public async Task ItRunPowershellScriptTestsAsync() | ||
// { | ||
// // test power shell | ||
// var ps = @"Write-Output ""hello world"""; | ||
// await this.TestPowershellCodeSnippet(_interactiveService, ps, "hello world"); | ||
// } | ||
[Fact] | ||
public async Task ItRunPowershellScriptTestsAsync() | ||
{ | ||
// test power shell | ||
var ps = @"Write-Output ""hello world"""; | ||
await this.TestPowershellCodeSnippet(_interactiveService, ps, "hello world"); | ||
} | ||
|
||
// private async Task TestPowershellCodeSnippet(InteractiveService service, string code, string expectedOutput) | ||
// { | ||
// var result = await service.SubmitPowershellCodeAsync(code, CancellationToken.None); | ||
// result.Should().StartWith(expectedOutput); | ||
// } | ||
private async Task TestPowershellCodeSnippet(InteractiveService service, string code, string expectedOutput) | ||
{ | ||
var result = await service.SubmitPowershellCodeAsync(code, CancellationToken.None); | ||
result.Should().StartWith(expectedOutput); | ||
} | ||
|
||
// private async Task TestCSharpCodeSnippet(InteractiveService service, string code, string expectedOutput) | ||
// { | ||
// var result = await service.SubmitCSharpCodeAsync(code, CancellationToken.None); | ||
// result.Should().StartWith(expectedOutput); | ||
// } | ||
//} | ||
private async Task TestCSharpCodeSnippet(InteractiveService service, string code, string expectedOutput) | ||
{ | ||
var result = await service.SubmitCSharpCodeAsync(code, CancellationToken.None); | ||
result.Should().StartWith(expectedOutput); | ||
} | ||
} |
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