Skip to content

Commit 02e5cfb

Browse files
Avoid flakiness in template tests around URL validity checking (#59195)
1 parent 9e04c78 commit 02e5cfb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/ProjectTemplates/Shared/AspNetProcess.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,19 @@ public async Task ContainsLinks(Page page)
171171
else
172172
{
173173
Assert.True(string.Equals(anchor.Href, expectedLink), $"Expected next link to be {expectedLink} but it was {anchor.Href}.");
174-
var result = await RetryHelper.RetryRequest(async () =>
174+
175+
if (!string.Equals(anchor.Protocol, "https:") || string.Equals(anchor.HostName, "localhost", StringComparison.OrdinalIgnoreCase))
175176
{
176-
return await _httpClient.GetAsync(anchor.Href);
177-
}, logger: NullLogger.Instance);
177+
// This is a relative or same-site URI, so verify it goes to a real destination within the app.
178+
// We don't do this for external (absolute) URIs as it would introduce flakiness, and the code
179+
// above already checks that the URI is what we expect.
180+
var result = await RetryHelper.RetryRequest(async () =>
181+
{
182+
return await _httpClient.GetAsync(anchor.Href);
183+
}, logger: NullLogger.Instance);
178184

179-
Assert.True(IsSuccessStatusCode(result), $"{anchor.Href} is a broken link!");
185+
Assert.True(IsSuccessStatusCode(result), $"{anchor.Href} is a broken link!");
186+
}
180187
}
181188
}
182189
}

0 commit comments

Comments
 (0)