Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid flakiness in template tests around URL validity checking #59195

Merged
merged 4 commits into from
Nov 27, 2024

Conversation

SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented Nov 27, 2024

We've had several failures in Templates.Mvc.Test.MvcTemplateTest.MvcTemplate_IndividualAuth recently with the error:

https://learn.microsoft.com/aspnet/core is a broken link!

Example build: https://dev.azure.com/dnceng-public/public/_build/results?buildId=880536

This is purely a flaky test issue and not a product bug. That link is actually valid. We just have some issue validating that when running in CI sometimes. I propose to fix this by changing the test logic not to make a real HTTP request to check the link is valid if it's an external (absolute) link.

There's no reason for us to be checking that external links are valid in CI. We just need to check that the template produces the links we expect (which it already does anyway). Any reliance on making requests to external sites during CI are possible sources of flakiness.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 27, 2024
@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review November 27, 2024 15:11
@SteveSandersonMS SteveSandersonMS requested a review from a team November 27, 2024 15:12
@@ -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:"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness here, can we check also that the host is not localhost or 127.0.0.1? Just in case we emit any absolute link in the templates.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense - I've added a check for localhost.

I haven't added one for 127.0.0.1 as it would be extraordinary and certainly wrong for someone to add such a link to the templates. The tests explicitly list all the URLs we expect to see, so we'd definitely know about it if someone added a link like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteveSandersonMS that's fair. I was thinking more in terms of absolute links generated automatically, not something written up by hand.

@SteveSandersonMS SteveSandersonMS enabled auto-merge (squash) November 27, 2024 16:05
@SteveSandersonMS SteveSandersonMS merged commit 02e5cfb into main Nov 27, 2024
27 checks passed
@SteveSandersonMS SteveSandersonMS deleted the stevesa/fix-template-test-flaky-link-checks branch November 27, 2024 17:33
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants