Skip to content

Stabilize distributed trace pipeline tests - #5958

Merged
hoyosjs merged 3 commits into
mainfrom
juhoyosa/ci-flake-investigation
Aug 11, 2026
Merged

hoyosjs merged 3 commits into
mainfrom
juhoyosa/ci-flake-investigation

Conversation

@hoyosjs

@hoyosjs hoyosjs commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Fix a race in DistributedTracesPipeline where EventPipe processing could begin while OnEventSourceAvailable was suspended in an asynchronous PipelineStarted callback, before the activity event handler was registered. Register the handler before the first await so activities emitted during logger startup are captured instead of dropped.

The tests now also wait for the target runtime to install its ActivitySource listener and keep the pipeline open until the expected activity is consumed.

No API breaking changes. Observable lifecycle behavior changes: Log may overlap an asynchronous PipelineStarted callback, and startup events are no longer dropped.

hoyosjs added 2 commits August 8, 2026 18:15
Wait for the distributed tracing event handler to be ready before waking the tracee, and wait for activity delivery before stopping the pipeline.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: ee7094e3-aa37-4474-b595-d1ed5a1d2764
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: ee7094e3-aa37-4474-b595-d1ed5a1d2764
@hoyosjs
hoyosjs marked this pull request as ready for review August 10, 2026 21:44
@hoyosjs
hoyosjs requested a review from a team as a code owner August 10, 2026 21:44
Copilot AI lite review requested due to automatic review settings August 10, 2026 21:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce flakiness in distributed trace pipeline unit tests by synchronizing “pipeline ready” and “tracee begins emitting” so the ActivitySource listener is installed before activities are produced and the pipeline remains open until the expected activity is consumed.

Changes:

  • Delay PipelineStarted signaling in DistributedTracesPipeline until after the consumer handler is registered.
  • Extend PipelineTestUtilities.ExecutePipelineWithTracee to optionally wait for a “pipeline started” task before waking the tracee.
  • Update the EventPipe tracee to optionally wait until ActivitySource.HasListeners() before starting the test body, and update trace tests to coordinate start/stop via TCS signals.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/PipelineTestUtilities.cs Adds optional pipelineStartedTask gating to reduce readiness race windows before waking the tracee.
src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTracesPipelineUnitTests.cs Adds pipeline/activity synchronization via TCS and updates tracee args to wait for ActivitySource listener installation.
src/tests/CommonTestRunner/Debuggees/EventPipeTracee/Program.cs Adds WaitForActivitySourceListener mode to delay activity emission until the runtime listener is installed.
src/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTraces/DistributedTracesPipeline.cs Registers Dynamic.All handler before reporting pipeline startup to loggers.
Suppressed comments (4)

src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTracesPipelineUnitTests.cs:92

  • Same invariance issue as above: TaskCompletionSource<object?> cannot be passed to ExecutePipelineWithTracee where TaskCompletionSource<object> is expected. Use TaskCompletionSource<object> consistently within this test file.
            TaskCompletionSource<object?> pipelineStartedSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
            TaskCompletionSource<object?> activityLoggedSource = new(TaskCreationOptions.RunContinuationsAsynchronously);
            TestActivityLogger logger = new(pipelineStartedSource, activityLoggedSource);

src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTracesPipelineUnitTests.cs:149

  • After switching the test TCS types to TaskCompletionSource<object>, the logger should also use the same generic type. Consider using a single static non-null object as the signal value to avoid allocating a new object each time TrySetResult is called.
            private readonly TaskCompletionSource<object?> _pipelineStartedSource;
            private readonly TaskCompletionSource<object?> _activityLoggedSource;

            public TestActivityLogger(
                TaskCompletionSource<object?> pipelineStartedSource,
                TaskCompletionSource<object?> activityLoggedSource)
            {
                _pipelineStartedSource = pipelineStartedSource;
                _activityLoggedSource = activityLoggedSource;
            }

src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTracesPipelineUnitTests.cs:159

  • If the logger's completion sources are TaskCompletionSource<object>, passing null to TrySetResult will produce nullable warnings (and can be treated as errors). Use a non-null signal value (e.g., the s_signal object) when completing the TCS.
                LoggedActivities.Add((activity, tags.ToArray()));
                _activityLoggedSource.TrySetResult(null);
            }

src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/DistributedTracesPipelineUnitTests.cs:165

  • Same as in Log: if _pipelineStartedSource is TaskCompletionSource<object>, complete it with a non-null value (e.g., s_signal) to avoid nullable warnings/errors under #nullable enable.
            public Task PipelineStarted(CancellationToken token)
            {
                _pipelineStartedSource.TrySetResult(null);
                return Task.CompletedTask;
            }

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: ee7094e3-aa37-4474-b595-d1ed5a1d2764
@hoyosjs
hoyosjs enabled auto-merge (squash) August 11, 2026 01:13
@hoyosjs
hoyosjs merged commit 66ffffc into main Aug 11, 2026
25 checks passed
@hoyosjs
hoyosjs deleted the juhoyosa/ci-flake-investigation branch August 11, 2026 09:26
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants