|
| 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