-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
akka-testkitAkka.NET Testkit issuesAkka.NET Testkit issues
Milestone
Description
Problem
TestKit's WaitUntilTestActorIsReady
uses Thread.Sleep(10)
in a tight loop, which:
- Always waits minimum 10ms even if TestActor is ready in microseconds
- Blocks thread pool threads unnecessarily
- Exacerbates thread starvation under high CPU load (e.g., CI with 2 CPUs)
- Causes "Timeout waiting for test actor to be ready" failures
Root Cause
The TestActor (a simple system actor) typically starts in microseconds, but Thread.Sleep(10)
forces a minimum 10ms wait. Under resource pressure, this blocking wait makes thread pool starvation worse, leading to timeouts.
Proposed Solution
Replace Thread.Sleep(10)
with SpinWait
which:
- Spins for ~10-20 microseconds (detects ready TestActor almost instantly)
- Then yields to other threads progressively
- Eventually sleeps if needed
- Adapts to system load automatically
Benefits
- Faster test startup (microseconds vs 10ms minimum)
- Better behavior under load (proper yielding)
- No breaking changes
- Reduces CI timeout failures
Metadata
Metadata
Assignees
Labels
akka-testkitAkka.NET Testkit issuesAkka.NET Testkit issues