Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support configuring fail point in RAII style #62

Merged
merged 2 commits into from
Jul 26, 2022
Merged

Conversation

tabokie
Copy link
Member

@tabokie tabokie commented Jun 24, 2022

It is very easy to write failpoint tests without freeing up the failpoint in the end.

Signed-off-by: tabokie xy.tao@outlook.com

Signed-off-by: tabokie <xy.tao@outlook.com>
@tabokie
Copy link
Member Author

tabokie commented Jun 24, 2022

@BusyJay What do you think

@BusyJay
Copy link
Member

BusyJay commented Jun 24, 2022

Why not use FailScenario?

@tabokie
Copy link
Member Author

tabokie commented Jun 24, 2022

User might not want to configure a global hook that applies to all failpoint tests (like we do in TiKV). If they don't do that, they have to add additional two lines for every tests. FailGuard appears easier to use.

I already used similar thing in Raft Engine (https://github.com/tikv/raft-engine/blob/1a9dd43a74a6ff93c176670e584db6ec520b6953/tests/failpoints/test_io_error.rs#L155), it's really natural to use.

Also, with respect to TiKV's implementation, calling teardown after the test closure is executed is not safe. Some threads might already be joined (and blocked on failpoint) inside the test closure (via custom Drop implementation).

@BusyJay
Copy link
Member

BusyJay commented Jun 24, 2022

User might not want to configure a global hook that applies to all failpoint tests (like we do in TiKV

Actually, TiKV configures global hook using its own way.

I already used similar thing in Raft Engine (https://github.com/tikv/raft-engine/blob/1a9dd43a74a6ff93c176670e584db6ec520b6953/tests/failpoints/test_io_error.rs#L155), it's really natural to use.

Your usage is wrong. Technically, there is only one global failpoint registry, so without synchronization, failpoint configuration set by any cases will affect other cases as well. Hence executing cases in sequential order is required.

Some threads might already be joined (and blocked on failpoint) inside the test closure (via custom Drop implementation).

It doesn't matter. Teardown will wake up all blocking threads.

@tabokie
Copy link
Member Author

tabokie commented Jun 24, 2022

Actually, TiKV configures global hook using its own way.

I'm saying user might not want to go over the trouble to doing a configuration like this.

Your usage is wrong.

You are looking at the wrong thing. I'm demonstrating that using FailGuard can make one test case much easier to manage. The failpoint tests in Raft Engine is all run with one threads (and documented).

I see that there are two things with failpoint tests. (1) failpoint cleanup (2) exclusive ownership to global registry. FailGuard only offers a new way to deal with (1).

It doesn't matter. Teardown will wake up all blocking threads.

It does matter. As I explained, the object destruction can be called inside the test closure. That means the process will be blocked inside without getting a chance to call the teardown outside the closure.

To see it in action, I have observed two cases that appear to be caused by forgetting to remove failpoints after test:
tikv/tikv@3767f2b

Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

src/lib.rs Outdated
/// Configure the actions for a fail point during the lifetime of the returning object.
///
/// Read documentation of [`cfg_callback`] for more details.
pub fn new_callback<S, F>(name: S, f: F) -> Result<FailGuard, String>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be named with_callback.

Signed-off-by: tabokie <xy.tao@outlook.com>
@tabokie
Copy link
Member Author

tabokie commented Jul 26, 2022

@BusyJay I can't merge this.

@BusyJay BusyJay merged commit eb67db9 into tikv:master Jul 26, 2022
@tabokie tabokie deleted the raii branch July 26, 2022 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants