Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tests/Aspire.Hosting.MySql.Tests/MySqlFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,18 +575,15 @@ public async Task MySql_WithPersistentLifetime_ReusesContainers(bool useMultiple

var rns = app.Services.GetRequiredService<ResourceNotificationService>();

var resourceEvent = await rns.WaitForResourceHealthyAsync("resource", cts.Token);
var mySqlId = await GetContainerIdAsync(rns, "resource", cts.Token);

var mySqlId2 = "";

if (useMultipleInstances)
{
resourceEvent = await rns.WaitForResourceHealthyAsync("resource2", cts.Token);
mySqlId2 = await GetContainerIdAsync(rns, "resource2", cts.Token);
}

resourceEvent = await rns.WaitForResourceHealthyAsync("phpmyadmin", cts.Token);
var phpMyAdminId = await GetContainerIdAsync(rns, "phpmyadmin", cts.Token);;

await app.StopAsync(cts.Token).WaitAsync(cts.Token);
Expand All @@ -596,6 +593,7 @@ public async Task MySql_WithPersistentLifetime_ReusesContainers(bool useMultiple

static async Task<string?> GetContainerIdAsync(ResourceNotificationService rns, string resourceName, CancellationToken cancellationToken)
{
await rns.WaitForResourceHealthyAsync(resourceName, cancellationToken);
var resourceEvent = await rns.WaitForResourceAsync(resourceName, (evt) =>
{
return evt.Snapshot.Properties.FirstOrDefault(x => x.Name == "container.id")?.Value != null;
Expand Down
17 changes: 10 additions & 7 deletions tests/Aspire.Hosting.PostgreSQL.Tests/PostgresFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,22 +562,25 @@ public async Task Postgres_WithPersistentLifetime_ReusesContainers()

var rns = app.Services.GetRequiredService<ResourceNotificationService>();

var resourceEvent = await rns.WaitForResourceHealthyAsync("resource", cts.Token);
var postgresId = GetContainerId(resourceEvent);
var postgresId = await GetContainerIdAsync(rns, "resource", cts.Token);

resourceEvent = await rns.WaitForResourceHealthyAsync("pgweb", cts.Token);
var pgWebId = GetContainerId(resourceEvent);
var pgWebId = await GetContainerIdAsync(rns, "pgweb", cts.Token);

resourceEvent = await rns.WaitForResourceHealthyAsync("pgadmin", cts.Token);
var pgadminId = GetContainerId(resourceEvent);
var pgadminId = await GetContainerIdAsync(rns, "pgadmin", cts.Token);

await app.StopAsync(cts.Token).WaitAsync(TimeSpan.FromMinutes(1), cts.Token);

return [postgresId, pgWebId, pgadminId];
}

static string? GetContainerId(ResourceEvent resourceEvent)
static async Task<string?> GetContainerIdAsync(ResourceNotificationService rns, string resourceName, CancellationToken cancellationToken)
{
await rns.WaitForResourceHealthyAsync(resourceName, cancellationToken);
var resourceEvent = await rns.WaitForResourceAsync(resourceName, (evt) =>
{
return evt.Snapshot.Properties.FirstOrDefault(x => x.Name == "container.id")?.Value != null;
}, cancellationToken);

return resourceEvent.Snapshot.Properties.FirstOrDefault(x => x.Name == "container.id")?.Value?.ToString();
}
}
Expand Down