From 7d01bc61368d912460e28daf8ea2edb228bfde24 Mon Sep 17 00:00:00 2001 From: Ryan Sweet Date: Wed, 11 Dec 2024 12:59:02 -0800 Subject: [PATCH] adds integration test for the InMemoryRuntime (#4659) * adds integration test for the InMemoryRuntime * format * expand timeout for in memory runtime tests --- dotnet/AutoGen.sln | 7 +++ .../HelloAgent.AppHost.csproj | 21 +++++++++ .../HelloAgent.AppHost/Program.cs | 10 +++++ .../Properties/launchSettings.json | 43 +++++++++++++++++++ .../InMemoryRuntimeIntegrationTests.cs | 43 +++++++++++++++++++ ...Microsoft.AutoGen.Integration.Tests.csproj | 2 + 6 files changed, 126 insertions(+) create mode 100644 dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/HelloAgent.AppHost.csproj create mode 100644 dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Program.cs create mode 100644 dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Properties/launchSettings.json create mode 100644 dotnet/test/Microsoft.AutoGen.Integration.Tests/InMemoryRuntimeIntegrationTests.cs diff --git a/dotnet/AutoGen.sln b/dotnet/AutoGen.sln index 21c1a62a3195..b01a59f7189b 100644 --- a/dotnet/AutoGen.sln +++ b/dotnet/AutoGen.sln @@ -134,6 +134,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AutoGen.Agents.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Integration.Tests", "test\Microsoft.AutoGen.Integration.Tests\Microsoft.AutoGen.Integration.Tests.csproj", "{D04C6153-8EAF-4E54-9852-52CEC1BE8D31}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloAgent.AppHost", "test\Microsoft.AutoGen.Integration.Tests.AppHosts\HelloAgent.AppHost\HelloAgent.AppHost.csproj", "{99D7766B-076F-4E6F-A8D2-3DF1DAFA2599}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -348,6 +350,10 @@ Global {D04C6153-8EAF-4E54-9852-52CEC1BE8D31}.Debug|Any CPU.Build.0 = Debug|Any CPU {D04C6153-8EAF-4E54-9852-52CEC1BE8D31}.Release|Any CPU.ActiveCfg = Release|Any CPU {D04C6153-8EAF-4E54-9852-52CEC1BE8D31}.Release|Any CPU.Build.0 = Release|Any CPU + {99D7766B-076F-4E6F-A8D2-3DF1DAFA2599}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99D7766B-076F-4E6F-A8D2-3DF1DAFA2599}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99D7766B-076F-4E6F-A8D2-3DF1DAFA2599}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99D7766B-076F-4E6F-A8D2-3DF1DAFA2599}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -409,6 +415,7 @@ Global {65059914-5527-4A00-9308-9FAF23D5E85A} = {18BF8DD7-0585-48BF-8F97-AD333080CE06} {394FDAF8-74F9-4977-94A5-3371737EB774} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} {D04C6153-8EAF-4E54-9852-52CEC1BE8D31} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} + {99D7766B-076F-4E6F-A8D2-3DF1DAFA2599} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {93384647-528D-46C8-922C-8DB36A382F0B} diff --git a/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/HelloAgent.AppHost.csproj b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/HelloAgent.AppHost.csproj new file mode 100644 index 000000000000..441d48d18cb5 --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/HelloAgent.AppHost.csproj @@ -0,0 +1,21 @@ + + + + + + Exe + net8.0 + enable + enable + true + + + + + + + + + + + diff --git a/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Program.cs b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Program.cs new file mode 100644 index 000000000000..3234a7abab9f --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Program.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Program.cs + +using Microsoft.Extensions.Hosting; + +var appHost = DistributedApplication.CreateBuilder(); +appHost.AddProject("HelloAgentsDotNetInMemoryRuntime"); +var app = appHost.Build(); +await app.StartAsync(); +await app.WaitForShutdownAsync(); diff --git a/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Properties/launchSettings.json b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Properties/launchSettings.json new file mode 100644 index 000000000000..ea78f2933fdb --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Integration.Tests.AppHosts/HelloAgent.AppHost/Properties/launchSettings.json @@ -0,0 +1,43 @@ +{ + "profiles": { + "https": { + "commandName": "Project", + "launchBrowser": true, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:15887;http://localhost:15888", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + //"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:16037", + "DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "https://localhost:16038", + "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:17037", + "DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true" + } + }, + "http": { + "commandName": "Project", + "launchBrowser": true, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:15888", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + //"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16031", + "DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL": "http://localhost:16032", + "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17031", + "DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true", + "ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true" + } + }, + "generate-manifest": { + "commandName": "Project", + "dotnetRunMessages": true, + "commandLineArgs": "--publisher manifest --output-path aspire-manifest.json", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development" + } + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json" +} diff --git a/dotnet/test/Microsoft.AutoGen.Integration.Tests/InMemoryRuntimeIntegrationTests.cs b/dotnet/test/Microsoft.AutoGen.Integration.Tests/InMemoryRuntimeIntegrationTests.cs new file mode 100644 index 000000000000..0795cf8be61d --- /dev/null +++ b/dotnet/test/Microsoft.AutoGen.Integration.Tests/InMemoryRuntimeIntegrationTests.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// InMemoryRuntimeIntegrationTests.cs +using Xunit.Abstractions; + +namespace Microsoft.AutoGen.Integration.Tests; + +public class InMemoryRuntimeIntegrationTests(ITestOutputHelper testOutput) +{ + + [Theory, Trait("type", "integration")] + [MemberData(nameof(AppHostAssemblies))] + public async Task HelloAgentsE2EInMemory(string appHostAssemblyPath) + { + var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostAssemblyPath, testOutput); + await using var app = await appHost.BuildAsync().WaitAsync(TimeSpan.FromSeconds(15)); + + await app.StartAsync().WaitAsync(TimeSpan.FromSeconds(120)); + await app.WaitForResourcesAsync().WaitAsync(TimeSpan.FromSeconds(120)); + + await app.StartAsync().WaitAsync(TimeSpan.FromSeconds(120)); + await app.WaitForResourcesAsync().WaitAsync(TimeSpan.FromSeconds(120)); + + //sleep 5 seconds to make sure the app is running + await Task.Delay(15000); + app.EnsureNoErrorsLogged(); + app.EnsureLogContains("Hello World"); + app.EnsureLogContains("HelloAgents said Goodbye"); + + await app.StopAsync().WaitAsync(TimeSpan.FromSeconds(15)); + } + public static TheoryData AppHostAssemblies() + { + var appHostAssemblies = GetSamplesAppHostAssemblyPaths(); + var theoryData = new TheoryData(); + return new(appHostAssemblies.Select(p => Path.GetRelativePath(AppContext.BaseDirectory, p))); + } + private static IEnumerable GetSamplesAppHostAssemblyPaths() + { + // All the AppHost projects are referenced by this project so we can find them by looking for all their assemblies in the base directory + return Directory.GetFiles(AppContext.BaseDirectory, "HelloAgent.AppHost.dll") + .Where(fileName => !fileName.EndsWith("Aspire.Hosting.AppHost.dll", StringComparison.OrdinalIgnoreCase)); + } +} diff --git a/dotnet/test/Microsoft.AutoGen.Integration.Tests/Microsoft.AutoGen.Integration.Tests.csproj b/dotnet/test/Microsoft.AutoGen.Integration.Tests/Microsoft.AutoGen.Integration.Tests.csproj index 0f3adc1c38a7..2ef1763c3db5 100644 --- a/dotnet/test/Microsoft.AutoGen.Integration.Tests/Microsoft.AutoGen.Integration.Tests.csproj +++ b/dotnet/test/Microsoft.AutoGen.Integration.Tests/Microsoft.AutoGen.Integration.Tests.csproj @@ -29,6 +29,8 @@ + +