-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for dependent resources before depolying the .dacpac (#380)
* Wait for dependent resources before depolying the .dacpac fixes #373 * fix up * move call * Add test to verify wait for dependent resource --------- Co-authored-by: Alireza Baloochi <[email protected]>
- Loading branch information
Showing
5 changed files
with
90 additions
and
12 deletions.
There are no files selected for viewing
17 changes: 12 additions & 5 deletions
17
...-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var server = builder.AddSqlServer("sql") | ||
.AddDatabase("TargetDatabase"); | ||
var server = builder.AddSqlServer("sql"); | ||
|
||
builder.AddSqlProject<Projects.SdkProject>("sdk-project") | ||
.WithReference(server); | ||
var database = server.AddDatabase("TargetDatabase"); | ||
|
||
var otherDatabase = server.AddDatabase("OtherTargetDatabase"); | ||
|
||
var sdkProject = builder.AddSqlProject<Projects.SdkProject>("sdk-project") | ||
.WithReference(database); | ||
|
||
var otherProject = builder.AddSqlProject<Projects.SdkProject>("other-sdk-project") | ||
.WithReference(otherDatabase) | ||
.WaitForCompletion(sdkProject); | ||
|
||
builder.AddSqlPackage<Packages.ErikEJ_Dacpac_Chinook>("chinook") | ||
.WithReference(server); | ||
.WithReference(database); | ||
|
||
builder.Build().Run(); |
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
68 changes: 68 additions & 0 deletions
68
tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/FunctionalTests.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,68 @@ | ||
using Aspire.Components.Common.Tests; | ||
using Aspire.Hosting; | ||
using Aspire.Hosting.Utils; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Projects; | ||
using Xunit.Abstractions; | ||
|
||
namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; | ||
|
||
[RequiresDocker] | ||
public class FunctionalTests(ITestOutputHelper testOutputHelper) | ||
{ | ||
[Fact] | ||
public async Task VerifyPublishSqlProjectWaitForDependentResources() | ||
{ | ||
var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10)); | ||
using var builder = TestDistributedApplicationBuilder.Create(testOutputHelper); | ||
|
||
var healthCheckTcs = new TaskCompletionSource<HealthCheckResult>(); | ||
builder.Services.AddHealthChecks().AddAsyncCheck("blocking_check", () => | ||
{ | ||
return healthCheckTcs.Task; | ||
}); | ||
|
||
var resource = builder.AddSqlServer("resource") | ||
.WithHealthCheck("blocking_check"); | ||
|
||
var database = resource.AddDatabase("TargetDatabase"); | ||
|
||
var otherDatabase = resource.AddDatabase("OtherTargetDatabase"); | ||
|
||
var dependentResource = builder.AddSqlProject<Projects.SdkProject>("dependentresource") | ||
.WithReference(database); | ||
|
||
var otherDependentResource = builder.AddSqlProject<Projects.SdkProject>("other-sdk-project") | ||
.WithReference(otherDatabase) | ||
.WaitForCompletion(dependentResource); | ||
|
||
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, "Pending", cts.Token); | ||
|
||
await rns.WaitForResourceAsync(otherDependentResource.Resource.Name, "Pending", 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, "Publishing", cts.Token); | ||
|
||
await rns.WaitForResourceAsync(dependentResource.Resource.Name, KnownResourceStates.Finished, cts.Token); | ||
|
||
await rns.WaitForResourceAsync(otherDependentResource.Resource.Name, "Publishing", cts.Token); | ||
|
||
await rns.WaitForResourceAsync(otherDependentResource.Resource.Name, KnownResourceStates.Finished, cts.Token); | ||
|
||
await pendingStart; | ||
|
||
await app.StopAsync(); | ||
} | ||
} |