Repository navigation
Architecture
Faultline runs the entire simulation on a single thread via a deterministic event pump:
-
Drain ready continuations: If
ReadyQueueis non-empty, pick the next item usingSimRandom(SimSchedulingPolicy.RandomInterleaving) or index0(SimSchedulingPolicy.Fifo), restoreSimContextfor itsSimHost, and invoke it. -
Advance virtual time: When
ReadyQueueis empty, dequeue the earliest(TimestampTicks, SequenceId)from theEventQueuepriority queue, advanceCurrentTime, and dispatch the event. -
Detect deadlocks: If both queues are empty while the root scenario task is incomplete, throw
SimDeadlockExceptionwith the exact reproductionSeed.
Each virtual host is stored in SimContext.CurrentHost (AsyncLocal<SimHost?>). Because ExecutionContext flows automatically across await boundaries, every intercepted call (DateTime.UtcNow, Random.Shared, Task.Delay) automatically resolves to the calling host's skewed SimClock and forked SimRandom without passing context parameters through application code.
When completing simulated TaskCompletionSource instances, SimEngine temporarily clears SynchronizationContext.Current around TrySetResult(). This ensures internal BCL combinators like Task.WhenAll resolve synchronously on the simulation thread (never escaping to the CLR ThreadPool), while async/await continuations that captured SimSynchronizationContext are forced back through ReadyQueue for seeded interleaving.