Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit d833354

Browse files
committed
*: update readme & add an example
Signed-off-by: Chojan Shang <[email protected]>
1 parent 9bc988b commit d833354

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# fail-rs
1+
# failpoints, another fail-rsS
22

3-
[![CI](https://github.com/tikv/fail-rs/workflows/CI/badge.svg)](https://github.com/tikv/fail-rs/actions)
4-
[![Crates.io](https://img.shields.io/crates/v/fail.svg?maxAge=2592000)](https://crates.io/crates/fail)
3+
[![CI](https://github.com/ritelabs/failpoints/workflows/CI/badge.svg)](https://github.com/ritelabs/failpoints/actions)
4+
[![Crates.io](https://img.shields.io/crates/v/failpoints.svg?maxAge=2592000)](https://crates.io/crates/failpoints)
55

6-
[Documentation](https://docs.rs/fail).
6+
[Documentation](https://docs.rs/failpoints).
77

8-
A fail point implementation for Rust.
8+
A failpoints implementation for Rust.
99

1010
Fail points are code instrumentations that allow errors and other behavior to be injected dynamically at runtime, primarily for testing purposes. Fail points are flexible and can be configured to exhibit a variety of behavior, including panics, early returns, and sleeping. They can be controlled both programmatically and via the environment, and can be triggered conditionally and probabilistically.
1111

@@ -17,19 +17,19 @@ First, add this to your `Cargo.toml`:
1717

1818
```toml
1919
[dependencies]
20-
fail = "0.4"
20+
failpoints = "0.1"
2121
```
2222

23-
Now you can import the `fail_point!` macro from the `fail` crate and use it to inject dynamic failures.
23+
Now you can import the `failpoint!` macro from the `failpoints` crate and use it to inject dynamic failures.
2424
Fail points generation by this macro is disabled by default, and can be enabled where relevant with the `failpoints` Cargo feature.
2525

2626
As an example, here's a simple program that uses a fail point to simulate an I/O panic:
2727

2828
```rust
29-
use fail::{fail_point, FailScenario};
29+
use failpoints::{failpoint, FailScenario};
3030

3131
fn do_fallible_work() {
32-
fail_point!("read-dir");
32+
failpoint!("read-dir");
3333
let _dir: Vec<_> = std::fs::read_dir(".").unwrap().collect();
3434
// ... do some work on the directory ...
3535
}
@@ -47,25 +47,21 @@ Here, the program calls `unwrap` on the result of `read_dir`, a function that re
4747
When the program is run normally it just prints "done":
4848

4949
```sh
50-
$ cargo run --features fail/failpoints
51-
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
52-
Running `target/debug/failpointtest`
50+
$ cargo run
51+
Finished dev [unoptimized + debuginfo] target(s) in 1.18s
52+
Running `target/debug/failpoint`
5353
done
5454
```
5555

5656
But now, by setting the `FAILPOINTS` variable we can see what happens if the `read_dir` fails:
5757

5858
```
59-
FAILPOINTS=read-dir=panic cargo run --features fail/failpoints
59+
$ FAILPOINTS=read-dir=panic cargo run --features failpoints/failpoints
6060
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
61-
Running `target/debug/failpointtest`
62-
thread 'main' panicked at 'failpoint read-dir panic', /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/fail-0.2.0/src/lib.rs:286:25
63-
note: Run with `RUST_BACKTRACE=1` for a backtrace.
61+
Running `target/debug/failpoint`
62+
thread 'main' panicked at 'failpoint read-dir panic', /home/psiace/Projects/ritelabs/dev/failpoints/src/lib.rs:498:25
63+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
6464
```
6565

66-
For further information see the [API documentation](https://docs.rs/fail).
67-
68-
69-
## TODO
66+
For further information see the [API documentation](https://docs.rs/failpoints).
7067

71-
Triggering a fail point via the HTTP API is planned but not implemented yet.

examples/failpoint/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "failpoint"
3+
version = "0.1.0"
4+
authors = ["Chojan Shang <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
failpoints = { path = "../.." }

examples/failpoint/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use failpoints::{failpoint, FailScenario};
2+
3+
fn do_fallible_work() {
4+
failpoint!("read-dir");
5+
let _dir: Vec<_> = std::fs::read_dir(".").unwrap().collect();
6+
// ... do some work on the directory ...
7+
}
8+
9+
fn main() {
10+
let scenario = FailScenario::setup();
11+
do_fallible_work();
12+
scenario.teardown();
13+
println!("done");
14+
}

0 commit comments

Comments
 (0)