PropertyDamage.Nemesis.ClockSkew (PropertyDamage v0.2.0)
View SourceSimulate clock skew and time anomalies.
Provides a virtual clock that can be skewed forward or backward, useful for testing time-sensitive logic like TTLs, rate limiting, scheduling, and expiration handling.
Configuration
:skew_ms- Amount to shift time by (positive = future, negative = past):drift_rate- Clock drift rate (1.0 = normal, 1.1 = 10% fast, 0.9 = 10% slow):duration_ms- How long the skew persists (default: 5000ms):mode-:instant(jump) or:gradual(drift)
Virtual Clock
This nemesis provides a virtual clock via PropertyDamage.Nemesis.ClockSkew.now/0.
Your adapter should use this instead of System.system_time/0 to be testable:
defmodule MyAdapter do
def get_current_time do
PropertyDamage.Nemesis.ClockSkew.now()
end
endExample
def commands do
[
{CreateSession, weight: 5},
{CheckSessionExpiry, weight: 5},
{PropertyDamage.Nemesis.ClockSkew, weight: 1}
]
endTesting Behavior
With clock skew, your system should:
- Handle time going "backward" gracefully
- Not break when time jumps forward
- Tolerate clock drift between nodes
Summary
Functions
Check if clock skew is currently active.
Get the current skew configuration, if any.
Get the current virtual time.
Functions
@spec active?() :: boolean()
Check if clock skew is currently active.
@spec current_skew() :: map() | nil
Get the current skew configuration, if any.
@spec now() :: integer()
Get the current virtual time.
If clock skew is active, returns adjusted time. Otherwise returns real time.
Use this in your adapter instead of System.system_time/0.