Skip to main content

Module chaos

Module chaos 

Source
Expand description

Fault injection primitives for testing Redis client resilience.

This module provides operations for simulating failures in Redis topologies: killing nodes, freezing processes (SIGSTOP/SIGCONT), triggering failovers, and more. All operations work with the handle types returned by the server, cluster, and sentinel builders.

Unix-only: the node-kill and freeze/resume operations send POSIX signals via kill. See the crate-level “Platform Support” docs for details.

§Example

use redis_server_wrapper::{RedisCluster, chaos};
use std::time::Duration;

let cluster = RedisCluster::builder()
    .masters(3)
    .replicas_per_master(1)
    .base_port(7100)
    .start()
    .await
    .unwrap();

// Freeze a node (SIGSTOP) -- it stops processing but stays in memory.
chaos::freeze_node(cluster.node(0));

// ... test client behavior with a frozen node ...

// Resume the node (SIGCONT).
chaos::resume_node(cluster.node(0));

Structs§

ReshardGuard
Holds a hash slot in the MIGRATING/IMPORTING state so tests can deterministically observe -ASK redirects, then finishes or reverts the migration.

Functions§

fill_memory
Fill a node with count keys holding fixed-size values.
flushall
Flush all data from a node.
freeze_master_by_slot
Freeze the master node that owns a given hash slot.
freeze_node
Freeze a node by sending SIGSTOP.
kill_master_by_key
Kill the master node that owns the hash slot for a given key.
kill_master_by_slot
Kill the master node that owns a given hash slot.
kill_node
Kill a node immediately with SIGKILL.
migrate_slot
Migrate a single hash slot from one master to another.
migrate_slots
Migrate a range of hash slots from one master to another.
partition
Simulate a network partition by freezing every node not in reachable.
pause_node
Freeze a node for a fixed duration, then resume it automatically.
recover
Resume all nodes in a cluster by sending SIGCONT.
resume_node
Resume a frozen node by sending SIGCONT.
slow_down
Pause client connections for a duration using CLIENT PAUSE.
trigger_failover
Trigger a CLUSTER FAILOVER on a replica node.
trigger_save
Trigger a background RDB save.