Skip to content

.Net: don't use a mutable static counter for tests that can run in parallel#11004

Merged
adamsitnik merged 1 commit intomicrosoft:mainfrom
adamsitnik:noSharedStaticState
Mar 18, 2025
Merged

.Net: don't use a mutable static counter for tests that can run in parallel#11004
adamsitnik merged 1 commit intomicrosoft:mainfrom
adamsitnik:noSharedStaticState

Conversation

@adamsitnik
Copy link
Copy Markdown
Member

By default, xUnit runs tests in parallel. What we were doing so far was having a static, mutable counter that some tests were setting to 0, while other could use in the meantime (increment or read and assert).

I've changed it to use a static dictionary of counters, where the name of the step is the key. So each step has it's own counter.

fixes #11001

@adamsitnik adamsitnik requested a review from a team as a code owner March 17, 2025 13:49
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label Mar 17, 2025
@github-actions github-actions Bot changed the title don't use a mutable static counter for tests that can run in parallel .Net: don't use a mutable static counter for tests that can run in parallel Mar 17, 2025
@adamsitnik adamsitnik enabled auto-merge March 17, 2025 15:45
@adamsitnik adamsitnik added this pull request to the merge queue Mar 18, 2025
Merged via the queue into microsoft:main with commit 886e822 Mar 18, 2025
22 checks passed
jcruzmot-te pushed a commit to thousandeyes/aia-semantic-kernel that referenced this pull request Sep 15, 2025
…rallel (microsoft#11004)

By default, xUnit runs tests in parallel. What we were doing so far was
having a static, mutable counter that some tests were setting to 0,
while other could use in the meantime (increment or read and assert).

I've changed it to use a static dictionary of counters, where the name
of the step is the key. So each step has it's own counter.

fixes microsoft#11001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: UnitTests.LocalMapTests.ProcessMapResultWithTargetExtraAsync is flaky

3 participants