PropertyDamage.Nemesis.SlowIO (PropertyDamage v0.2.0)

View Source

Simulate slow I/O operations.

Intercepts I/O operations and adds artificial delay, useful for testing behavior under slow disk, database, or external service conditions.

Configuration

  • :delay_ms - Delay to add to each I/O operation (default: 100ms)
  • :jitter_ms - Random jitter ± this value (default: 0)
  • :target - What to slow: :all, :reads, :writes (default: :all)
  • :duration_ms - How long the slowdown persists (default: 5000ms)

Usage

This nemesis sets a flag that your adapter should check:

defmodule MyAdapter do
  def read_file(path) do
    # Check for slow I/O nemesis
    if PropertyDamage.Nemesis.SlowIO.should_delay?(:reads) do
      PropertyDamage.Nemesis.SlowIO.apply_delay()
    end

    File.read(path)
  end
end

Example

def commands do
  [
    {ReadDocument, weight: 5},
    {WriteDocument, weight: 5},
    {PropertyDamage.Nemesis.SlowIO, weight: 1}
  ]
end

Testing Behavior

With slow I/O, your system should:

  • Handle timeouts appropriately
  • Not block user-facing operations
  • Maintain consistency despite delays

Summary

Functions

Check if slow I/O is currently active.

Apply the configured I/O delay. Call this in your adapter when performing I/O.

Get the current I/O delay configuration, if any.

Check if I/O delay should be applied for the given operation type.

Functions

active?()

@spec active?() :: boolean()

Check if slow I/O is currently active.

apply_delay()

@spec apply_delay() :: :ok

Apply the configured I/O delay. Call this in your adapter when performing I/O.

current_config()

@spec current_config() :: map() | nil

Get the current I/O delay configuration, if any.

should_delay?(operation_type \\ :all)

@spec should_delay?(atom()) :: boolean()

Check if I/O delay should be applied for the given operation type.