Skip to content

Commit

Permalink
Avoid flakiness in template tests around URL validity checking (#59195)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS authored Nov 27, 2024
1 parent 9e04c78 commit 02e5cfb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ProjectTemplates/Shared/AspNetProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@ public async Task ContainsLinks(Page page)
else
{
Assert.True(string.Equals(anchor.Href, expectedLink), $"Expected next link to be {expectedLink} but it was {anchor.Href}.");
var result = await RetryHelper.RetryRequest(async () =>

if (!string.Equals(anchor.Protocol, "https:") || string.Equals(anchor.HostName, "localhost", StringComparison.OrdinalIgnoreCase))
{
return await _httpClient.GetAsync(anchor.Href);
}, logger: NullLogger.Instance);
// This is a relative or same-site URI, so verify it goes to a real destination within the app.
// We don't do this for external (absolute) URIs as it would introduce flakiness, and the code
// above already checks that the URI is what we expect.
var result = await RetryHelper.RetryRequest(async () =>
{
return await _httpClient.GetAsync(anchor.Href);
}, logger: NullLogger.Instance);

Assert.True(IsSuccessStatusCode(result), $"{anchor.Href} is a broken link!");
Assert.True(IsSuccessStatusCode(result), $"{anchor.Href} is a broken link!");
}
}
}
}
Expand Down

0 comments on commit 02e5cfb

Please sign in to comment.