Skip to content

Run test on Linux and Mac #45642

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

Merged
merged 6 commits into from
Jan 20, 2023
Merged

Run test on Linux and Mac #45642

merged 6 commits into from
Jan 20, 2023

Conversation

Youssef1313
Copy link
Member

This used to fail. I wanted to confirm if this is still an issue.

@ghost ghost added area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework community-contribution Indicates that the PR has been added by a community member labels Dec 17, 2022
@ghost
Copy link

ghost commented Dec 17, 2022

Thanks for your PR, @Youssef1313. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Youssef1313
Copy link
Member Author

@captainsafia I found an interesting thing here. The clone of the repository happens on Windows, so test files are checked out with CRLF line endings. Then, tests are run in Windows, Linux, and macOS against the repo that was cloned on Windows with CRLF:

image

Should the repo be renormalized when sent for each OS?

I still think Roslyn could be better here and detect the existing line endings, but still maybe something in CI here could be improved.

@captainsafia
Copy link
Member

@Youssef1313 Thanks for looking into this?

Should the repo be renormalized when sent for each OS?

@dougbu @wtgodbe Do you know if it is possible to configure git to target new lines to each target machine? How do we handle tests that are sensitive to OS-specific line endings elsewhere (assuming those exist)?

I still think Roslyn could be better here and detect the existing line endings, but still maybe something in CI here could be improved.

Agree with this! I don't see any reason for Roslyn testing to be this sensitive when it comes to comparing line-endings, especially because AFAIK things like generators/analyzers aren't meant to be environment-specific. Is there an issue tracking this on the Roslyn side?

@Youssef1313
Copy link
Member Author

I don't see any reason for Roslyn testing to be this sensitive when it comes to comparing line-endings

Testing library intentionally compares line endings to catch bugs. By my comment, I meant that I was expecting Roslyn itself to do best effort guessing line ending instead of using Environment.NewLine (when end_of_line isn't set), but that ended up being by-design.

@Youssef1313
Copy link
Member Author

Do you know if it is possible to configure git to target new lines to each target machine?

I think this is already done in .gitattribtues, but this works on fresh clones.

If the repo is cloned on Ubuntu, then it's LF. If it's cloned on Windows, then it's CRLF. (which is the correct behavior)

What happens though is the repo being cloned on Windows, and then (as far as I understand) sent to other machines using SendHelixJob. I don't know how SendHelixJob works, but whatever the way is, it keeps line endings the same.

I'm not sure if this is something to improve on dotnet/arcade?

@wtgodbe
Copy link
Member

wtgodbe commented Jan 13, 2023

@dougbu @wtgodbe Do you know if it is possible to configure git to target new lines to each target machine? How do we handle tests that are sensitive to OS-specific line endings elsewhere (assuming those exist)?

For tests like these that are dependent on OS line-ending, I think they aren't suited for Helix. I suggest skipping them on helix so that they run in the on-machine build jobs. You can do so like the following:

[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/6720", Queues = "All.OSX")]

In this case you'd skip it on all queues:

[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/<new issue>"]

@Youssef1313
Copy link
Member Author

There are couple of solutions to resolve this without skipping the test.

  • Replace all line endings with the Environment.NewLine both in input source and fixed source. (last commit does that for this specific test to see whether it passes CI)
  • Introduce an editorconfig for codefix tests that sets end_of_line = lf, then the test infrastructure would replace \r\n with \n from inputs

Not sure which approach you'd prefer. Currently I'm testing with the first one being applied specifically to the single problematic test.

@Youssef1313 Youssef1313 marked this pull request as ready for review January 14, 2023 09:14
@captainsafia
Copy link
Member

Introduce an editorconfig for codefix tests that sets end_of_line = lf, then the test infrastructure would replace \r\n with \n from inputs

How do you go about configuring the editorconfig? Will it be done in a way that conflicts with the repo-level one or does the configuration happen in source?

Replace all line endings with the Environment.NewLine both in input source and fixed source. (last commit does that for this specific test to see whether it passes CI)

I'm fine with doing this as part of the verifier.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jan 17, 2023

How do you go about configuring the editorconfig? Will it be done in a way that conflicts with the repo-level one or does the configuration happen in source?

In source, via TestState.AnalyzerConfigFiles. So the .editorconfig will simply be a "string" in the test that doesn't mess up with repo-level .editorconfig.

The current approach should be passing, but let me know if you prefer a different approach.

@captainsafia
Copy link
Member

It seems like both approaches, when done properly, can be achieved by modifying the base Verifier class. I have a slight preference towards the editorconfig option since it seems clearer to document.

@Youssef1313 Youssef1313 requested review from a team, dougbu and wtgodbe as code owners January 19, 2023 07:31
@Youssef1313
Copy link
Member Author

It seems like both approaches, when done properly, can be achieved by modifying the base Verifier class. I have a slight preference towards the editorconfig option since it seems clearer to document.

Done in last commit. Let's see if it will pass.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jan 19, 2023

2023-01-19T08:23:04.0578516Z [xUnit.net 00:00:28.46]       content of '/0/Test0.cs' did not match. Diff shown with expected as baseline:
2023-01-19T08:23:04.0580088Z [xUnit.net 00:00:28.46]        using Microsoft.AspNetCore.Hosting;<LF>
2023-01-19T08:23:04.0581492Z [xUnit.net 00:00:28.46]       -using Microsoft.AspNetCore.Http;<LF>
2023-01-19T08:23:04.0582983Z [xUnit.net 00:00:28.46]       +using Microsoft.AspNetCore.Http;<CR><LF>
2023-01-19T08:23:04.0584410Z [xUnit.net 00:00:28.47]        using Microsoft.AspNetCore.Mvc;<LF>

I wasn't expecting that. This failure happens on Linux. Trying a different approach now to set the option directly in OptionSet

@Youssef1313
Copy link
Member Author

Still doesn't work. I'll revert back to the initial approach 😕 .

@dougbu
Copy link
Contributor

dougbu commented Jan 19, 2023

What is different about this one test❔ Numerous tests use CSharpCodeFixVerifier with strings from the source files.

I guess the question might be "Is this really the only test that adds new newlines when fixing C#❔" or perhaps "Does the analyzer here have a bug❔"

@Youssef1313
Copy link
Member Author

Youssef1313 commented Jan 19, 2023

@dougbu I think not so many tests out there are adding new usings/lines so that's why it wasn't caught.

The analyzer/codefix don't have bugs. The codefix is just adding an AddImportsAnnotation. Nothing more.

@wtgodbe
Copy link
Member

wtgodbe commented Jan 19, 2023

There are couple of solutions to resolve this without skipping the test.

To be clear, my suggestion (SkipOnHelix) won't make it so the tests don't run - it will tell the test to run on the local machine rather than on Helix. All of our tests run on only one or the other.

@Youssef1313
Copy link
Member Author

There are couple of solutions to resolve this without skipping the test.

To be clear, my suggestion (SkipOnHelix) won't make it so the tests don't run - it will tell the test to run on the local machine rather than on Helix. All of our tests run on only one or the other.

Thanks for the clarification!

@captainsafia would you like me to try this?

@dougbu
Copy link
Contributor

dougbu commented Jan 19, 2023

Given we want to get rid of every test job except the Helix one, I'm a fan of the current approach. As long as the test area owners agree, let's do it this way.

@wtgodbe
Copy link
Member

wtgodbe commented Jan 19, 2023

Given we want to get rid of every test job except the Helix one, I'm a fan of the current approach. As long as the test area owners agree, let's do it this way.

Is that tracked somewhere?

@dougbu
Copy link
Contributor

dougbu commented Jan 19, 2023

Given we want to get rid of every test job except the Helix one, I'm a fan of the current approach. As long as the test area owners agree, let's do it this way.

Is that tracked somewhere?

I recall that @HaoK closed the overall issue for moving everything to Helix because we had individual issues for each area that seemed stuck on build agents. See #10424, #18799, #27609, #38818, and #39420 for example.

More generally, testing on build agents is a waste of resources and not where we want to be. So, let's not make the problem worse (even if most of the above issues have been considered low priority lately).

@captainsafia
Copy link
Member

Thanks for the clarification!

@captainsafia would you like me to try this?

The editorconfig strategy didn't work, but does the ReplaceLineEndings one work? I would favor that being done here.

I also think addressing the issue well be prudent since we have more analyzers/codefixers coming down the pipe.

@Youssef1313
Copy link
Member Author

The editorconfig strategy didn't work, but does the ReplaceLineEndings one work? I would favor that being done here.

I prefer moving this workaround to CSharpAnalyzerVerifier only when encountered in more tests.

@captainsafia
Copy link
Member

The editorconfig strategy didn't work, but does the ReplaceLineEndings one work? I would favor that being done here.

I prefer moving this workaround to CSharpAnalyzerVerifier only when encountered in more tests.

Fair enough, in that case can you document what the workaround is for in case we run into it in future tests?

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM assuming we add a code comment clarifying what this is for

@captainsafia
Copy link
Member

/azp run

@captainsafia captainsafia enabled auto-merge (squash) January 20, 2023 04:07
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Youssef1313
Copy link
Member Author

/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/SourceBuild/SourceBuildArcadeBuild.targets(170,5): error MSB3073: The command "git submodule foreach --recursive '/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/SourceBuild/git-clone-to-dir.sh --source . --dest "/__w/1/s/artifacts/source-build/self/src/$sm_path" --clean'" exited with code 128. [/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/Build.proj]

@captainsafia Can you restart the source-build job please?

@captainsafia
Copy link
Member

/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/SourceBuild/SourceBuildArcadeBuild.targets(170,5): error MSB3073: The command "git submodule foreach --recursive '/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/SourceBuild/git-clone-to-dir.sh --source . --dest "/__w/1/s/artifacts/source-build/self/src/$sm_path" --clean'" exited with code 128. [/__w/1/s/.packages/microsoft.dotnet.arcade.sdk/8.0.0-beta.23063.7/tools/Build.proj]

@captainsafia Can you restart the source-build job please?

There are some issues with source build that are pending a fix that are causing this failure. Rekicking the build is not likely to do anything.

@dotnet/aspnet-build How are we handling things in the meantime? Are we able to force-merge?

@wtgodbe
Copy link
Member

wtgodbe commented Jan 20, 2023

The failure is due to the build agents, not anything in this repo: dotnet/source-build#3111. Some agents are new enough that they won't fail, some are not - in general you can ping me or doug to force-merge, or just re-run the source build job until it works (it's short). I'll force merge this one.

@wtgodbe wtgodbe disabled auto-merge January 20, 2023 17:30
@wtgodbe wtgodbe merged commit ed77f14 into dotnet:main Jan 20, 2023
@ghost ghost added this to the 8.0-preview1 milestone Jan 20, 2023
@Youssef1313 Youssef1313 deleted the patch-2 branch January 20, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants