Skip to content

fix: timing-based test assertions are inherently flaky #4876

Closed as not planned

Description

@thomhurst

Description

Several tests verify parallel/non-parallel execution by checking DateTime overlaps, which are inherently fragile:

ParallelTests.cs and NotInParallelTests.cs

Use DateTimeRange overlaps to verify parallel/sequential execution. DateTime precision depends on system clock granularity. On slow CI systems, tests might complete too quickly for overlap detection.

TimeoutTests1.cs (Lines 18-19)

Tight timing assertion expecting test to complete between 4-60 seconds. Fragile on resource-constrained CI.

AdaptiveParallelismTests.cs

CPU-intensive loop using DateTime.UtcNow comparisons (system clock dependent). 1000 repetitions × 1s delay = 16+ minutes per test method.

Suggested Fix

  • Replace DateTime overlap checks with Interlocked concurrent execution counters
  • Use event-based synchronization (TaskCompletionSource) instead of hard timeouts
  • Widen timing windows with documented rationale
  • Separate AdaptiveParallelismTests into a [Category("Performance")] suite

Activity

  1. github-actions commented on Mar 21, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  2. github-actions commented on Mar 26, 2026

    @github-actions
    Contributor

    This issue was closed because it has been stalled for 5 days with no activity.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalebugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions