Skip to content

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

@thomhurst

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

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