fail-rs icon indicating copy to clipboard operation
fail-rs copied to clipboard

support async failpoints

Open tabokie opened this issue 2 years ago • 4 comments

  • Added async_fail_point macro, it's usage is exactly the same as fail_point, but must be placed in an asynchronous context.
  • sleep and pause command sent to the async fail point will not block async runtime.
  • In addition, cfg_async_callback is added to inject custom async logic.

Signed-off-by: Xinye [email protected]

tabokie avatar Oct 25 '23 06:10 tabokie

Seems duplicated with #58.

BusyJay avatar Oct 25 '23 08:10 BusyJay

Seems duplicated with #58.

From the looks of it, #58 doesn't support async sleep and runtime async callback. This PR supports them, but doesn't support specifying a compile-time async callback (the one implemented in-place with fail_point).

I can't figure out an elegant way to unify async and sync version of fail_point!(name, callback). And I'm reluctant to go with #58 and make all fail_point!(name, callback) return async blocks, because most of the time that isn't necessary. If the user want to inject custom async logic, they can always use the more powerful cfg_callback.

tabokie avatar Oct 25 '23 09:10 tabokie

I can't figure out an elegant way to unify async and sync version of fail_point!(name, callback). And I'm reluctant to go with https://github.com/tikv/fail-rs/pull/58 and make all fail_point!(name, callback) return async blocks, because most of the time that isn't necessary. If the user want to inject custom async logic, they can always use the more powerful cfg_callback.

FYI, #58 defines two macros for sync (fail_point!()) and async(async_fail_point!()). It won't affect existing code.

waynexia avatar Oct 25 '23 10:10 waynexia

I can't figure out an elegant way to unify async and sync version of fail_point!(name, callback). And I'm reluctant to go with #58 and make all fail_point!(name, callback) return async blocks, because most of the time that isn't necessary. If the user want to inject custom async logic, they can always use the more powerful cfg_callback.

FYI, #58 defines two macros for sync (fail_point!()) and async(async_fail_point!()). It won't affect existing code.

I see, it is a slightly different mental model. Your idea is to only use async_fail_point when user want to inject async code. My idea is to always use async_fail_point in async context. In practice the latter is more versatile because we might not know what to inject beforehand.

And continue with my idea, it becomes important to allow user to write async_fail_point(name, || { Ok(()) }) instead of async_fail_point(name, || { async { Ok(()) } }.

tabokie avatar Oct 25 '23 14:10 tabokie