Skip to content

Commit cd1a61e

Browse files
authored
[tests] Fix some flaky tests in Aspire.Hosting.Azure.Tests (#5187)
* [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
1 parent 02a0bc6 commit cd1a61e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tests/Aspire.Hosting.Tests/Schema/SchemaTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ public void ValidateApplicationSamples(string testCaseName, Action<IDistributedA
195195
{
196196
_ = testCaseName;
197197

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

tests/Aspire.Hosting.Tests/Utils/ManifestUtils.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,20 @@ public static async Task<JsonNode[]> GetManifests(IResource[] resources)
6767

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

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

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

82-
var bicepText = await File.ReadAllTextAsync(path);
83+
var bicepText = await File.ReadAllTextAsync(Path.Combine(manifestDir, path));
8384
return (manifestNode, bicepText);
8485
}
8586
}

0 commit comments

Comments
 (0)