Klotho.Mock (klotho v0.1.2)
This is the backend is used in :test
environment.
The module gives control of the mocked time and provides inspection of triggered timers.
Summary
Functions
Freeze time. In frozen
mode, all calls to monotonic_time
and system_time
will return the same value. Timers will be not triggered unless warp is called.
The function is idempotent.
Reset the state of the time server. This
Return history of all messages (%Klotho.Mock.TimerMsg{}
) sent by triggered timers.
Most recent messages are first.
Unreeze time. In running
mode, all calls to monotonic_time
and system_time
will
start produce values increasing with "normal" monotonic time pace.
Timers will be triggered according to their schedule.
Warp time forward by timer_interval
milliseconds.
Regardless of the current mode (frozen or running), all the timers
that are due to trigger within the next timer_interval
milliseconds
will be triggered after warp.
Warp time forward by timer_interval
in unit
.
Regardless of the current mode (frozen or running), all the timers
that are due to trigger within the next timer_interval
milliseconds
will be triggered after warp.
Functions
freeze()
@spec freeze() :: :ok
Freeze time. In frozen
mode, all calls to monotonic_time
and system_time
will return the same value. Timers will be not triggered unless warp is called.
The function is idempotent.
reset()
@spec reset() :: :ok
Reset the state of the time server. This
- resets the time to the actual current time;
- cleans timer history;
- resets the mode to
running
; - cancels all timers.
timer_event_history()
@spec timer_event_history() :: [Klotho.Mock.TimerMsg.t()]
Return history of all messages (%Klotho.Mock.TimerMsg{}
) sent by triggered timers.
Most recent messages are first.
unfreeze()
@spec unfreeze() :: :ok
Unreeze time. In running
mode, all calls to monotonic_time
and system_time
will
start produce values increasing with "normal" monotonic time pace.
Timers will be triggered according to their schedule.
warp_by(timer_interval)
@spec warp_by(non_neg_integer()) :: :ok
Warp time forward by timer_interval
milliseconds.
Regardless of the current mode (frozen or running), all the timers
that are due to trigger within the next timer_interval
milliseconds
will be triggered after warp.
warp_by(timer_interval, unit)
@spec warp_by(non_neg_integer(), :erlang.time_unit()) :: :ok
Warp time forward by timer_interval
in unit
.
Regardless of the current mode (frozen or running), all the timers
that are due to trigger within the next timer_interval
milliseconds
will be triggered after warp.