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.
rysweet-4150-xlang-ci-test (microsoft#4596)
adds aspire-based integration test that validates: * registration * subscriptions * event delivery * python -> .NET server -> python subscriber * .NET -> .NET server -> python subscriber * python -> .NET server -> .NET subscriber
- Loading branch information
Showing
8 changed files
with
625 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
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
120 changes: 120 additions & 0 deletions
120
dotnet/test/Microsoft.AutoGen.Integration.Tests/HelloAppHostIntegrationTests.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,120 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// HelloAppHostIntegrationTests.cs | ||
|
||
using System.Text.Json; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AutoGen.Integration.Tests; | ||
|
||
public class HelloAppHostIntegrationTests(ITestOutputHelper testOutput) | ||
{ | ||
[Theory, Trait("type", "integration")] | ||
[MemberData(nameof(AppHostAssemblies))] | ||
public async Task AppHostRunsCleanly(string appHostPath) | ||
{ | ||
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, 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)); | ||
|
||
app.EnsureNoErrorsLogged(); | ||
await app.StopAsync().WaitAsync(TimeSpan.FromSeconds(15)); | ||
} | ||
|
||
[Theory, Trait("type", "integration")] | ||
[MemberData(nameof(TestEndpoints))] | ||
public async Task AppHostLogsHelloAgentE2E(TestEndpoints testEndpoints) | ||
{ | ||
var appHostName = testEndpoints.AppHost!; | ||
var appHostPath = $"{appHostName}.dll"; | ||
var appHost = await DistributedApplicationTestFactory.CreateAsync(appHostPath, 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)); | ||
if (testEndpoints.WaitForResources?.Count > 0) | ||
{ | ||
// Wait until each resource transitions to the required state | ||
var timeout = TimeSpan.FromMinutes(5); | ||
foreach (var (ResourceName, TargetState) in testEndpoints.WaitForResources) | ||
{ | ||
await app.WaitForResource(ResourceName, TargetState).WaitAsync(timeout); | ||
} | ||
} | ||
//sleep 5 seconds to make sure the app is running | ||
await Task.Delay(5000); | ||
app.EnsureNoErrorsLogged(); | ||
app.EnsureLogContains("HelloAgents said Goodbye"); | ||
app.EnsureLogContains("Wild Hello from Python!"); | ||
|
||
await app.StopAsync().WaitAsync(TimeSpan.FromSeconds(15)); | ||
} | ||
public static TheoryData<string> AppHostAssemblies() | ||
{ | ||
var appHostAssemblies = GetSamplesAppHostAssemblyPaths(); | ||
var theoryData = new TheoryData<string, bool>(); | ||
return new(appHostAssemblies.Select(p => Path.GetRelativePath(AppContext.BaseDirectory, p))); | ||
} | ||
|
||
public static TheoryData<TestEndpoints> TestEndpoints() => | ||
new([ | ||
new TestEndpoints("Hello.AppHost", new() { | ||
{ "backend", ["/"] } | ||
}), | ||
]); | ||
|
||
private static IEnumerable<string> 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, "*.AppHost.dll") | ||
.Where(fileName => !fileName.EndsWith("Aspire.Hosting.AppHost.dll", StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
|
||
public class TestEndpoints : IXunitSerializable | ||
{ | ||
// Required for deserialization | ||
public TestEndpoints() { } | ||
|
||
public TestEndpoints(string appHost, Dictionary<string, List<string>> resourceEndpoints) | ||
{ | ||
AppHost = appHost; | ||
ResourceEndpoints = resourceEndpoints; | ||
} | ||
|
||
public string? AppHost { get; set; } | ||
|
||
public List<ResourceWait>? WaitForResources { get; set; } | ||
|
||
public Dictionary<string, List<string>>? ResourceEndpoints { get; set; } | ||
|
||
public void Deserialize(IXunitSerializationInfo info) | ||
{ | ||
AppHost = info.GetValue<string>(nameof(AppHost)); | ||
WaitForResources = JsonSerializer.Deserialize<List<ResourceWait>>(info.GetValue<string>(nameof(WaitForResources))); | ||
ResourceEndpoints = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(info.GetValue<string>(nameof(ResourceEndpoints))); | ||
} | ||
|
||
public void Serialize(IXunitSerializationInfo info) | ||
{ | ||
info.AddValue(nameof(AppHost), AppHost); | ||
info.AddValue(nameof(WaitForResources), JsonSerializer.Serialize(WaitForResources)); | ||
info.AddValue(nameof(ResourceEndpoints), JsonSerializer.Serialize(ResourceEndpoints)); | ||
} | ||
|
||
public override string? ToString() => $"{AppHost} ({ResourceEndpoints?.Count ?? 0} resources)"; | ||
|
||
public class ResourceWait(string resourceName, string targetState) | ||
{ | ||
public string ResourceName { get; } = resourceName; | ||
|
||
public string TargetState { get; } = targetState; | ||
|
||
public void Deconstruct(out string resourceName, out string targetState) | ||
{ | ||
resourceName = ResourceName; | ||
targetState = TargetState; | ||
} | ||
} | ||
} |
Oops, something went wrong.