Skip to content

Commit 2ad77eb

Browse files
authored
Fix GH Models lifetime (#10842)
1 parent 28f379f commit 2ad77eb

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/Aspire.Hosting.GitHub.Models/GitHubModelResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Aspire.Hosting.GitHub.Models;
88
/// <summary>
99
/// Represents a GitHub Model resource.
1010
/// </summary>
11-
public class GitHubModelResource : Resource, IResourceWithConnectionString, IResourceWithoutLifetime
11+
public class GitHubModelResource : Resource, IResourceWithConnectionString
1212
{
1313
internal ParameterResource DefaultKeyParameter { get; set; }
1414

tests/Aspire.Hosting.GitHub.Models.Tests/Aspire.Hosting.GitHub.Models.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<Compile Include="$(TestsSharedDir)AsyncTestHelpers.cs" Link="shared/AsyncTestHelpers.cs" />
9+
</ItemGroup>
10+
711
<ItemGroup>
812
<ProjectReference Include="..\..\src\Aspire.Hosting.GitHub.Models\Aspire.Hosting.GitHub.Models.csproj" />
913
<ProjectReference Include="..\..\src\Aspire.Hosting.Testing\Aspire.Hosting.Testing.csproj" />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Aspire.Hosting.ApplicationModel;
5+
using Aspire.Hosting.Utils;
6+
using Aspire.TestUtilities;
7+
using Microsoft.AspNetCore.InternalTesting;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Diagnostics.HealthChecks;
10+
11+
namespace Aspire.Hosting.GitHub.Models.Tests;
12+
13+
public class GitHubModelsFunctionalTests
14+
{
15+
[Fact]
16+
[RequiresDocker]
17+
public async Task DependentResourceWaitsForGitHubModelResourceWithHealthCheckToBeHealthy()
18+
{
19+
using var cts = new CancellationTokenSource(TestConstants.LongTimeoutDuration);
20+
21+
var healthCheckTcs = new TaskCompletionSource<HealthCheckResult>();
22+
23+
using var builder = TestDistributedApplicationBuilder.Create();
24+
builder.Configuration["Parameters:resource-gh-apikey"] = "test-api-key";
25+
26+
builder.Services.AddHealthChecks().AddAsyncCheck("blocking_check", () =>
27+
{
28+
return healthCheckTcs.Task;
29+
});
30+
31+
var resource = builder.AddGitHubModel("resource", "openai/gpt-4o-mini")
32+
.WithHealthCheck("blocking_check");
33+
34+
var dependentResource = builder.AddContainer("nginx", "mcr.microsoft.com/cbl-mariner/base/nginx", "1.22")
35+
.WaitFor(resource);
36+
37+
using var app = builder.Build();
38+
39+
var pendingStart = app.StartAsync(cts.Token);
40+
41+
await app.ResourceNotifications.WaitForResourceAsync(resource.Resource.Name, KnownResourceStates.Running, cts.Token);
42+
43+
await app.ResourceNotifications.WaitForResourceAsync(dependentResource.Resource.Name, KnownResourceStates.Waiting, cts.Token);
44+
45+
healthCheckTcs.SetResult(HealthCheckResult.Healthy());
46+
47+
await app.ResourceNotifications.WaitForResourceHealthyAsync(resource.Resource.Name, cts.Token);
48+
49+
await app.ResourceNotifications.WaitForResourceAsync(dependentResource.Resource.Name, KnownResourceStates.Running, cts.Token);
50+
51+
await pendingStart;
52+
53+
await app.StopAsync();
54+
}
55+
}

0 commit comments

Comments
 (0)