Macaw.Data.Clock.Manual (macaw_data v0.21.1)
View SourceA manual clock for tests (spec/01 §6.5), shipped in lib/ as test code the rules
allowlist names: a test drives every debounce, tick, backoff and timeout with it and
never sleeps (macaw spec/00 §4.4 rule 1).
{:ok, clock} = Macaw.Data.Clock.Manual.start_link(at: ~U[2026-11-16 12:00:00Z])
Macaw.Data.Clock.Manual.advance(clock, 250)It is a process holding the wall time, the monotonic milliseconds and the armed timers.
advance/2 moves both by ms and fires every timer due by then, in due order (two due
at once in the order they were armed), each sent before advance/2 answers. set/2
moves the wall time alone; the monotonic time never goes back.
Every call waits for the clock with no timeout of its own: a clock certain to answer is never a wall-clock budget, which a loaded suite outlasts (macaw_live#109), and a clock that never answers is the test's timeout's to report.
Summary
Functions
Moves the clock ms ahead, firing every timer due by then in due order: :ok.
Returns a specification to start this module under a supervisor.
The timers armed and not fired or canceled, as [{due_ms, pid, message}] in due order.
How many times the wall time has been read, so a test shows a pulse reads it once.
Moves the wall time to datetime: :ok. Timers are on the monotonic time and stay.
Starts a manual clock at at: (a UTC DateTime, required): {:ok, pid}, or
{:error, [{[:at], :required}]} / {:error, [{[:at], {:type, :time}}]}.
Functions
@spec advance(pid(), non_neg_integer()) :: :ok
Moves the clock ms ahead, firing every timer due by then in due order: :ok.
Returns a specification to start this module under a supervisor.
See Supervisor.
The timers armed and not fired or canceled, as [{due_ms, pid, message}] in due order.
@spec reads(pid()) :: non_neg_integer()
How many times the wall time has been read, so a test shows a pulse reads it once.
@spec set(pid(), DateTime.t()) :: :ok
Moves the wall time to datetime: :ok. Timers are on the monotonic time and stay.
@spec start_link(keyword()) :: GenServer.on_start() | {:error, [Macaw.Base.Fault.t()]}
Starts a manual clock at at: (a UTC DateTime, required): {:ok, pid}, or
{:error, [{[:at], :required}]} / {:error, [{[:at], {:type, :time}}]}.