Documentation Index
Fetch the complete documentation index at: https://docs.roboticks.io/llms.txt
Use this file to discover all available pages before exploring further.
Fault injection reference
roboticks.fault_injection ships four context managers that manipulate the rclpy DDS layer for the duration of a with block. For the task-oriented introduction with worked examples, see Testing → Fault injection; this page is the API reference.
drop_messages
Probabilistically drop messages on a topic.
Signature
| Parameter | Type | Constraint |
|---|---|---|
topic | str | Fully-qualified topic name. |
rate | float | 0.0 (drop nothing) to 1.0 (drop everything). |
seed | int | None | Optional RNG seed for reproducible drops. |
Behaviour
- Installs an interceptor on the topic at context entry; uninstalls at exit.
- Drops are evaluated per message, not per second. A rate of 0.5 drops roughly half the messages.
- If multiple
drop_messagesblocks nest on the same topic, the product of rates applies (composition is multiplicative). - Out-of-range
rateraisesValueErrorat entry.
Example
delay_messages
Add a fixed latency to every message on a topic.
Signature
| Parameter | Type | Constraint |
|---|---|---|
topic | str | Fully-qualified topic name. |
ms | int | Base latency in milliseconds. Must be ≥ 0. |
jitter_ms | int | Uniform jitter added to each message (±jitter_ms / 2). Defaults to 0. |
Behaviour
- Each intercepted message is held for
ms ± jitter_ms/2before being released to subscribers. - Holding is implemented as a
threading.Timerper message. High-rate topics with highmswill hold many in-flight messages; budget memory accordingly. - Order is preserved (per-topic FIFO).
Example
kill_node
SIGTERM a named node and assert it stays down for the duration of the block.
Signature
| Parameter | Type | Constraint |
|---|---|---|
name | str | Fully-qualified node name (e.g. /nav2_planner). |
signal | int | Signal to send. Defaults to SIGTERM. |
wait_for_exit | float | Seconds to wait for the process to actually exit. |
Returns (as context value)
ANodeKilledHandle with:
| Attribute | Description |
|---|---|
pid | PID of the killed process. |
started_at | Timestamp of the kill. |
respawned | True if a watchdog/respawn brought the node back during the block. |
Raises
LookupError— no node with that name visible on the ROS graph at entry.RuntimeError— process refused to exit withinwait_for_exit.
Example
corrupt_topic
Apply a mutator function to every message on a topic.
Signature
| Parameter | Type | Constraint |
|---|---|---|
topic | str | Fully-qualified topic name. |
mutator | Callable[[msg], msg] | Receives a deserialised message; must return one of the same type. |
Behaviour
- The mutator runs between the publisher and subscribers — every subscriber sees the mutated value.
- Mutator exceptions propagate up to the publishing thread and abort the test. Catch inside the mutator if you want resilient behaviour.
- The mutator may mutate in place and return the same object, or return a fresh one.
Example
Composition
All four context managers compose with each other and withmcap_capture:
DDS implementation notes
- Implemented via rclpy’s middleware plug-points — no DDS vendor extensions required.
- Per-test isolated: the interceptor installs into the current process only; other processes in a
launch_testinggraph see the un-faulted topic. - For across-process fault injection (e.g. fault a topic between two separately-launched nodes), use
launch_testingintegration and inject from inside the test process that owns the topic.
Limits
| Limit | Value | Notes |
|---|---|---|
Concurrent drop/delay per topic | 8 | More than 8 nested blocks raise. |
Concurrent corrupt per topic | 4 | More than 4 nested blocks raise. |
| Max delay per message | 60 s | Defends against unbounded queues. |
| Max in-flight delayed messages per topic | 1024 | Excess is silently dropped with a logger warning. |
Next
Fault injection tutorial
Task-oriented examples and decision tree.
Assertions
The natural pair with fault injection.
MCAP capture
Record the degraded signal for forensics.
Launch testing
Fault injection across a multi-process graph.