From e153e455596dec26e14800b1efd20f7c081c41c1 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Mon, 19 Aug 2024 00:57:33 -0700 Subject: [PATCH 1/2] dispose kernel after running test --- .../DotnetInteractiveServiceTest.cs | 131 +++++++++--------- ...netInteractiveStdioKernelConnectorTests.cs | 7 +- ...ocessDotnetInteractiveKernelBuilderTest.cs | 9 +- 3 files changed, 77 insertions(+), 70 deletions(-) diff --git a/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveServiceTest.cs b/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveServiceTest.cs index 2e215a65332f..aeec23a758bd 100644 --- a/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveServiceTest.cs +++ b/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveServiceTest.cs @@ -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); + } +} diff --git a/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveStdioKernelConnectorTests.cs b/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveStdioKernelConnectorTests.cs index 6bc361c72513..520d00c04c67 100644 --- a/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveStdioKernelConnectorTests.cs +++ b/dotnet/test/AutoGen.DotnetInteractive.Tests/DotnetInteractiveStdioKernelConnectorTests.cs @@ -10,7 +10,7 @@ namespace AutoGen.DotnetInteractive.Tests; [Collection("Sequential")] -public class DotnetInteractiveStdioKernelConnectorTests +public class DotnetInteractiveStdioKernelConnectorTests : IDisposable { private string _workingDir; private Kernel kernel; @@ -77,4 +77,9 @@ public async Task ItAddPythonKernelTestAsync() var result = await this.kernel.RunSubmitCodeCommandAsync(pythonCode, "python"); result.Should().Contain("Hello, World!"); } + + public void Dispose() + { + this.kernel.Dispose(); + } } diff --git a/dotnet/test/AutoGen.DotnetInteractive.Tests/InProcessDotnetInteractiveKernelBuilderTest.cs b/dotnet/test/AutoGen.DotnetInteractive.Tests/InProcessDotnetInteractiveKernelBuilderTest.cs index 517ee499efc1..fe2de74dd302 100644 --- a/dotnet/test/AutoGen.DotnetInteractive.Tests/InProcessDotnetInteractiveKernelBuilderTest.cs +++ b/dotnet/test/AutoGen.DotnetInteractive.Tests/InProcessDotnetInteractiveKernelBuilderTest.cs @@ -7,12 +7,13 @@ namespace AutoGen.DotnetInteractive.Tests; +[Collection("Sequential")] public class InProcessDotnetInteractiveKernelBuilderTest { [Fact] public async Task ItAddCSharpKernelTestAsync() { - var kernel = DotnetInteractiveKernelBuilder + using var kernel = DotnetInteractiveKernelBuilder .CreateEmptyInProcessKernelBuilder() .AddCSharpKernel() .Build(); @@ -29,7 +30,7 @@ public async Task ItAddCSharpKernelTestAsync() [Fact] public async Task ItAddPowershellKernelTestAsync() { - var kernel = DotnetInteractiveKernelBuilder + using var kernel = DotnetInteractiveKernelBuilder .CreateEmptyInProcessKernelBuilder() .AddPowershellKernel() .Build(); @@ -45,7 +46,7 @@ public async Task ItAddPowershellKernelTestAsync() [Fact] public async Task ItAddFSharpKernelTestAsync() { - var kernel = DotnetInteractiveKernelBuilder + using var kernel = DotnetInteractiveKernelBuilder .CreateEmptyInProcessKernelBuilder() .AddFSharpKernel() .Build(); @@ -62,7 +63,7 @@ public async Task ItAddFSharpKernelTestAsync() [Fact] public async Task ItAddPythonKernelTestAsync() { - var kernel = DotnetInteractiveKernelBuilder + using var kernel = DotnetInteractiveKernelBuilder .CreateEmptyInProcessKernelBuilder() .AddPythonKernel("python3") .Build(); From 14930a014e82face3e5b45e6c5acdb939073fa33 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Mon, 19 Aug 2024 14:20:27 -0700 Subject: [PATCH 2/2] add timeout --- .github/workflows/dotnet-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 1b53d0bde88f..7eca61861714 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -54,6 +54,7 @@ jobs: os: [ ubuntu-latest, macos-latest, windows-latest ] python-version: ["3.11"] runs-on: ${{ matrix.os }} + timeout-minutes: 30 steps: - uses: actions/checkout@v4 with: