-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First pass of getting Cosmos going with Health Checks. * Debugging persistent containers + cosmos + waitfor. * Add Cosmos emulator functional test. * Remove playground lifetime change. * Create CosmosClient once.
- Loading branch information
1 parent
e8b6e5f
commit 2cb078e
Showing
5 changed files
with
112 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.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,59 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Aspire.Components.Common.Tests; | ||
using Aspire.Hosting.ApplicationModel; | ||
using Aspire.Hosting.Utils; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Aspire.Hosting.Azure.Tests; | ||
|
||
public class AzureCosmosDBEmulatorFunctionalTests(ITestOutputHelper testOutputHelper) | ||
{ | ||
[Fact] | ||
[RequiresDocker] | ||
public async Task VerifyWaitForOnCosmosDBEmulatorBlocksDependentResources() | ||
{ | ||
// Cosmos can be pretty slow to spin up, lets give it plenty of time. | ||
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5)); | ||
using var builder = TestDistributedApplicationBuilder.Create(testOutputHelper); | ||
|
||
var healthCheckTcs = new TaskCompletionSource<HealthCheckResult>(); | ||
builder.Services.AddHealthChecks().AddAsyncCheck("blocking_check", () => | ||
{ | ||
return healthCheckTcs.Task; | ||
}); | ||
|
||
var resource = builder.AddAzureCosmosDB("resource") | ||
.RunAsEmulator() | ||
.WithHealthCheck("blocking_check"); | ||
|
||
var dependentResource = builder.AddAzureCosmosDB("dependentresource") | ||
.RunAsEmulator() | ||
.WaitFor(resource); | ||
|
||
using var app = builder.Build(); | ||
|
||
var pendingStart = app.StartAsync(cts.Token); | ||
|
||
var rns = app.Services.GetRequiredService<ResourceNotificationService>(); | ||
|
||
await rns.WaitForResourceAsync(resource.Resource.Name, KnownResourceStates.Running, cts.Token); | ||
|
||
await rns.WaitForResourceAsync(dependentResource.Resource.Name, KnownResourceStates.Waiting, cts.Token); | ||
|
||
healthCheckTcs.SetResult(HealthCheckResult.Healthy()); | ||
|
||
await rns.WaitForResourceAsync(resource.Resource.Name, (re => re.Snapshot.HealthStatus == HealthStatus.Healthy), cts.Token); | ||
|
||
await rns.WaitForResourceAsync(dependentResource.Resource.Name, KnownResourceStates.Running, cts.Token); | ||
|
||
await pendingStart; | ||
|
||
await app.StopAsync(); | ||
} | ||
|
||
} |