Skip to content

Commit

Permalink
[tests] Fix some flaky tests in Aspire.Hosting.Azure.Tests (#5187)
Browse files Browse the repository at this point in the history
* [tests] ValidateApplicationSamples: use a temporary path for generating the manifest

Other tests also generate and use `postgres.module.bicep` in the tests'
bindir, and these can run in parallel causing them to interfere with
each other.

Issue: #5174

* [tests] ManifestUtils.GetManifestWithBicep: generate in a temporary path

Avoid interfering with other tests by generating the bicep files in
per-test temporyary paths.

`AzureBicepResourceTests.AsAzurePostgresFlexibleServerViaRunMode`
uses `postgres.module.bicep` also, and that file can get overwritten by
other tests like in `AzureBicepResourceTests`.

Issue: #5113
  • Loading branch information
radical authored Aug 6, 2024
1 parent 02a0bc6 commit cd1a61e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/Aspire.Hosting.Tests/Schema/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public void ValidateApplicationSamples(string testCaseName, Action<IDistributedA
{
_ = testCaseName;

var builder = TestDistributedApplicationBuilder.Create(["--publisher", "manifest", "--output-path", "not-used.json"]);
string manifestDir = Directory.CreateTempSubdirectory(testCaseName).FullName;
var builder = TestDistributedApplicationBuilder.Create(["--publisher", "manifest", "--output-path", Path.Combine(manifestDir, "not-used.json")]);
builder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, JsonDocumentManifestPublisher>("manifest");
configurator(builder);

Expand Down
7 changes: 4 additions & 3 deletions tests/Aspire.Hosting.Tests/Utils/ManifestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,20 @@ public static async Task<JsonNode[]> GetManifests(IResource[] resources)

public static async Task<(JsonNode ManifestNode, string BicepText)> GetManifestWithBicep(IResource resource)
{
var manifestNode = await GetManifest(resource);
string manifestDir = Directory.CreateTempSubdirectory(resource.Name).FullName;
var manifestNode = await GetManifest(resource, manifestDir);

if (!manifestNode.AsObject().TryGetPropertyValue("path", out var pathNode))
{
throw new ArgumentException("Specified resource does not contain a path property.", nameof(resource));
}

if (pathNode?.ToString() is not { } path || !File.Exists(path))
if (pathNode?.ToString() is not { } path || !File.Exists(Path.Combine(manifestDir, path)))
{
throw new ArgumentException("Path node in resource is null, empty, or does not exist.", nameof(resource));
}

var bicepText = await File.ReadAllTextAsync(path);
var bicepText = await File.ReadAllTextAsync(Path.Combine(manifestDir, path));
return (manifestNode, bicepText);
}
}

0 comments on commit cd1a61e

Please sign in to comment.