KEMBAR78
Consolidate System.Private.Xml test projects by stephentoub · Pull Request #75499 · dotnet/runtime · GitHub
Skip to content

Conversation

@stephentoub
Copy link
Member

We currently have almost 30 test projects underneath System.Private.Xml\tests in various levels of nested directories. This makes it challenging to appropriately run all of the System.Private.Xml tests when making any changes to anything in S.P.Xml, and it makes it all but impossible to get meaningful code coverage information, which in turns significantly lowers our confidence about any changes being made to the library.

This PR consolidates almost all of them into a single System.Private.Xml.Tests projects. It is a mostly mechanical change, adding all of the relevant files to the single .csproj and deleting the individual csproj files. In some cases I added more specific namespaces to deal with conflicts. In others multiple projects were including the same files containing [Facts] and parameterizing them via statics that were supplied by individual files built only into the relevant projects; I fixed those by making the [Fact]s into [Theory]s and passing in all the relevant state. I also had to fix up some cases where tests were mutating global state that then conflicted with other tests.

    Discovering: System.Private.Xml.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Private.Xml.Tests (found 4734 of 4785 test cases)
    Starting:    System.Private.Xml.Tests (parallel test collections = on, max threads = 12)
    Finished:    System.Private.Xml.Tests
  === TEST EXECUTION SUMMARY ===
     System.Private.Xml.Tests  Total: 23714, Errors: 0, Failed: 0, Skipped: 0, Time: 64.213s

This explicitly does not:

  • Clean up any test code beyond the minimal necessary to get this to compile. Many of these tests are old and crusty and worthy of a complete rewrite, but I restrained myself.
  • Move or rename any files around.
  • Try to enable parallelization of the tests. That’d be good to do at some point to help with test execution time, but I didn’t want to change any tests beyond what was necessary.

I did run the fixer to remove unnecessary usings, as I’d added some usings as part of mechanically fixing this without paying attention to whether they were necessary or not.

There are just two test projects that remain separate: one for trimming, and one for serialization that runs some of the same tests but with a different compilation constant set for its build.

Fixes #75456

Resulting code coverage is now measurable but not great:

+--------------------+--------+--------+--------+
| Module             | Line   | Branch | Method |
+--------------------+--------+--------+--------+
| System.Private.Xml | 52.68% | 43.27% | 60.92% |
+--------------------+--------+--------+--------+

@stephentoub stephentoub added this to the 8.0.0 milestone Sep 13, 2022
@ghost
Copy link

ghost commented Sep 13, 2022

Tagging subscribers to this area: @dotnet/area-system-xml
See info in area-owners.md if you want to be subscribed.

Issue Details

We currently have almost 30 test projects underneath System.Private.Xml\tests in various levels of nested directories. This makes it challenging to appropriately run all of the System.Private.Xml tests when making any changes to anything in S.P.Xml, and it makes it all but impossible to get meaningful code coverage information, which in turns significantly lowers our confidence about any changes being made to the library.

This PR consolidates almost all of them into a single System.Private.Xml.Tests projects. It is a mostly mechanical change, adding all of the relevant files to the single .csproj and deleting the individual csproj files. In some cases I added more specific namespaces to deal with conflicts. In others multiple projects were including the same files containing [Facts] and parameterizing them via statics that were supplied by individual files built only into the relevant projects; I fixed those by making the [Fact]s into [Theory]s and passing in all the relevant state. I also had to fix up some cases where tests were mutating global state that then conflicted with other tests.

    Discovering: System.Private.Xml.Tests (method display = ClassAndMethod, method display options = None)
    Discovered:  System.Private.Xml.Tests (found 4734 of 4785 test cases)
    Starting:    System.Private.Xml.Tests (parallel test collections = on, max threads = 12)
    Finished:    System.Private.Xml.Tests
  === TEST EXECUTION SUMMARY ===
     System.Private.Xml.Tests  Total: 23714, Errors: 0, Failed: 0, Skipped: 0, Time: 64.213s

This explicitly does not:

  • Clean up any test code beyond the minimal necessary to get this to compile. Many of these tests are old and crusty and worthy of a complete rewrite, but I restrained myself.
  • Move or rename any files around.
  • Try to enable parallelization of the tests. That’d be good to do at some point to help with test execution time, but I didn’t want to change any tests beyond what was necessary.

I did run the fixer to remove unnecessary usings, as I’d added some usings as part of mechanically fixing this without paying attention to whether they were necessary or not.

There are just two test projects that remain separate: one for trimming, and one for serialization that runs some of the same tests but with a different compilation constant set for its build.

Fixes #75456

Resulting code coverage is now measurable but not great:

+--------------------+--------+--------+--------+
| Module             | Line   | Branch | Method |
+--------------------+--------+--------+--------+
| System.Private.Xml | 52.68% | 43.27% | 60.92% |
+--------------------+--------+--------+--------+
Author: stephentoub
Assignees: -
Labels:

area-System.Xml

Milestone: 8.0.0

@ghost ghost assigned stephentoub Sep 13, 2022
@danmoseley
Copy link
Member

Try to enable parallelization of the tests.

Is the default xunit parallelization disabled?

@stephentoub
Copy link
Member Author

stephentoub commented Sep 13, 2022

Is the default xunit parallelization disabled?

Yes. A bunch of the tests change process-wide state, e.g. setting various AppContext switches.

@danmoseley
Copy link
Member

Is this going to increase end to end test time then, as previously each library would potentially run concurrently with the others?

@stephentoub
Copy link
Member Author

Is this going to increase end to end test time then, as previously each library would potentially run concurrently with the others?

Considering the significant overhead associated with running a test suite in CI, I highly doubt it.

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

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

Please verify that there are actually 2 kinds of XPath implementation and not 3. Other than that looks good to me.

Thanks a lot for this cleanup - this has been a giant pain point.

@eiriktsarpalis
Copy link
Member

Is the default xunit parallelization disabled?

Yes. A bunch of the tests change process-wide state, e.g. setting various AppContext switches.

How many tests do this? Would it be feasible to use RemoteExecutor for those in a later change?

@stephentoub
Copy link
Member Author

Would it be feasible to use RemoteExecutor for those in a later change?

Yup.

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

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

I just double checked the old code - seems I misremembered and it looks good as is. Thanks again!

@stephentoub
Copy link
Member Author

I need to make some fixes to the xml linq test project which apparently pulls in some of the same shared files...

We currently have almost 30 test projects underneath System.Private.Xml\tests in various levels of nested directories.  This makes it challenging to appropriately run all of the System.Private.Xml tests when making any changes to anything in S.P.Xml, and it makes it all but impossible to get meaningful code coverage information, which in turns significantly lowers our confidence about any changes being made to the library.

This PR consolidates almost all of them into a single System.Private.Xml.Tests projects.  It is a mostly mechanical change, adding all of the relevant files to the single .csproj and deleting the individual csproj files.  In some cases I added more specific namespaces to deal with conflicts.  In others multiple projects were including the same files containing [Facts] and parameterizing them via statics that were supplied by individual files built only into the relevant projects; I fixed those by making the [Fact]s into [Theory]s and passing in all the relevant state.  I also had to fix up some cases where tests were mutating global state that then conflicted with other tests.

This explicitly does not:
- Clean up any test code beyond the minimal necessary to get this to compile.  Many of these tests are old and crusty and worthy of a complete rewrite, but I restrained myself.
- Move or rename any files around.
- Try to enable parallelization of the tests.  That’d be good to do at some point to help with test execution time, but I didn’t want to change any tests beyond what was necessary.

I did run the fixer to remove unnecessary usings, as I’d added some usings as part of mechanically fixing this without paying attention to whether they were necessary or not.

There are just two test projects that remain separate: one for trimming, and one for serialization that runs some of the same tests but with a different compilation constant set for its build.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate System.Private.Xml tests into a single csproj

4 participants