Skip to content

Fix flaky StateMachineAsync_CallstackStressWithVaryingDepths test. - #130337

Merged
lateralusX merged 1 commit into
dotnet:mainfrom
lateralusX:lateralusX/harden-StateMachineAsync-CallstackStressWithVariyingDepths-test
Jul 8, 2026
Merged

lateralusX merged 1 commit into
dotnet:mainfrom
lateralusX:lateralusX/harden-StateMachineAsync-CallstackStressWithVariyingDepths-test

Conversation

@lateralusX

Copy link
Copy Markdown
Member

Summary

Removes a fragile buffer-flush-count assertion from StateMachineAsync_CallstackStressWithVaryingDepths that has been intermittently failing in CI. The rest of the test — which validates async callstack frame data across 100 randomly-varying recursion depths — is unchanged.

Problem

The test ended with:

int bufferCount = 0;
ForEachEventBufferPayload(events, _ => bufferCount++);
AssertTrue(stream, bufferCount >= 3, $"Expected at least 3 buffer flushes, got {bufferCount}");

ForEachEventBufferPayload counts per-thread event-buffer payloads, so bufferCount is a function of both the total event volume and how the work happened to be distributed across threadpool threads.

Fix

Drop the buffer-flush-count assertion. It is:

  • Non-deterministic — depends on threadpool scheduling, not just the (seeded) workload.
  • Redundant — the buffer overflow / rent path is already exercised deterministically by StateMachineAsync max-depth stress test (Depth = byte.MaxValue, Iterations = 128), which overflows the per-thread buffer many times over.

The test retains its actual purpose: it still asserts every marker callstack has valid, resolvable frame data and that at least one marker callstack is emitted per iteration.

Risk

Test-only change; no product code touched. No loss of meaningful coverage.

Fixes:

#129938
#129871

Remove the buffer count assert since its depending on how test
executes and what threads it ends up hitting on the resume paths.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

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 fixes flakiness in the AsyncProfilerTests.StateMachineAsync_CallstackStressWithVaryingDepths test by removing a non-deterministic assertion that depends on how async work is scheduled across threads, while keeping the core validation of emitted async callstack frame data intact.

Changes:

  • Removed the “>= 3 buffer flushes” assertion based on ForEachEventBufferPayload from StateMachineAsync_CallstackStressWithVaryingDepths.
  • Kept the existing assertions that validate marker callstacks are emitted and contain resolvable, non-empty frame data.

@lateralusX
lateralusX merged commit aa7a6fd into dotnet:main Jul 8, 2026
87 of 89 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 10, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
…130337)

### Summary

Removes a fragile buffer-flush-count assertion from
StateMachineAsync_CallstackStressWithVaryingDepths that has been
intermittently failing in CI. The rest of the test — which validates
async callstack frame data across 100 randomly-varying recursion depths
— is unchanged.

### Problem

The test ended with:

   int bufferCount = 0;
   ForEachEventBufferPayload(events, _ => bufferCount++);
AssertTrue(stream, bufferCount >= 3, $"Expected at least 3 buffer
flushes, got {bufferCount}");

ForEachEventBufferPayload counts per-thread event-buffer payloads, so
bufferCount is a function of both the total event volume and how the
work happened to be distributed across threadpool threads.

### Fix

Drop the buffer-flush-count assertion. It is:

- Non-deterministic — depends on threadpool scheduling, not just the
(seeded) workload.
- Redundant — the buffer overflow / rent path is already exercised
deterministically by StateMachineAsync max-depth stress test (Depth =
byte.MaxValue, Iterations = 128), which overflows the per-thread buffer
many times over.

The test retains its actual purpose: it still asserts every marker
callstack has valid, resolvable frame data and that at least one marker
callstack is emitted per iteration.

### Risk

Test-only change; no product code touched. No loss of meaningful
coverage.

Fixes:

#129938
#129871
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 10, 2026
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.

3 participants