Serialize SelfLog-sharing tests to fix intermittent CarriesMessageTemplateProperties failure#73
Merged
Conversation
…plateProperties failure
KodrAus
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I saw the pipeline fail in the build and publish stage after my last pr merged. Some tests failed in the pipeline even if they worked on local dev machine so I had a look at it.
CI failed intermittently in the Testing stage on
net8.0/net9.0(passed onnet10.0/net48):CarriesMessageTemplatePropertiesenablesSelfLog, logs a message, asserts the capturedoutput is empty, and throws if not. The captured text was
"Enricher Failed"— the exceptionthrown by
EnricherTests.FailingEnricherIsHandled.Root cause
SelfLogis a process-global singleton (static Action<string>? _output) with no per-testisolation. The two tests sit in different xUnit collections, which xUnit runs in parallel by
default. When
FailingEnricherIsHandledtriggers its failing enricher during the window whereCarriesMessageTemplatePropertieshasSelfLog._outputpointed at itsStringWriter, thediagnostic write leaks into the other test's writer, making it throw the captured text.
It is timing-dependent (a race), which is why it surfaced on only 2 of 4 target frameworks in
this run and never reproduces locally — the .NET 10 / test-dependency bumps changed test
scheduling enough for the latent race to surface on CI. There is no product or test-logic
regression: the build, packaging, and the other 91 tests all passed with 0 warnings.
Fix
Put the two
SelfLog-sharing test classes in a single xUnit collection withDisableParallelization = trueso they execute sequentially against each other, eliminatingthe overlapping window. Other collections still run in parallel, so the suite stays fast.
Support/SelfLogCollection.cs—[CollectionDefinition("SelfLog", DisableParallelization = true)][Collection("SelfLog")]onSerilogLoggerTests[Collection("SelfLog")]onEnricherTestsValidation
I could not reproduce the failing tests on my dev machine so this needs to be validated in the pipeline runs.
Notes