A library for testing time-dependent GenServers and simulating actor systems using virtual time.
This library provides two main capabilities:
VirtualTimeGenServer: A drop-in replacement for GenServer that supports virtual time, allowing you to test time-dependent behaviors instantly without waiting for real time to pass.
ActorSimulation: A DSL for defining and simulating complex actor systems with message rates, patterns, and comprehensive statistics collection.
Quick Example
# Define a time-dependent GenServer
defmodule MyServer do
use VirtualTimeGenServer
def init(_) do
VirtualTimeGenServer.send_after(self(), :tick, 1000)
{:ok, %{count: 0}}
end
def handle_info(:tick, state) do
{:noreply, %{state | count: state.count + 1}}
end
end
# Test it with virtual time (instant!)
test "ticks 10 times in 10 seconds" do
{:ok, clock} = VirtualClock.start_link()
VirtualTimeGenServer.set_virtual_clock(clock)
{:ok, server} = MyServer.start_link(nil)
VirtualClock.advance(clock, 10_000) # Instant!
assert get_count(server) == 10
endModules
VirtualClock- Manages virtual time and scheduled eventsVirtualTimeGenServer- GenServer with virtual time supportActorSimulation- DSL for actor system simulation
See the README for comprehensive examples and usage patterns.