File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ log = { version = "0.4", features = ["std"] }
1818lazy_static = " 1.2"
1919rand = " 0.8"
2020
21+ [dev-dependencies ]
22+ tokio = { version = " 1.12.0" , default-features = false , features = [
23+ " rt" ,
24+ " macros" ,
25+ ] }
26+
2127[features ]
2228failpoints = []
2329
Original file line number Diff line number Diff line change @@ -797,6 +797,11 @@ macro_rules! fail_point {
797797 panic!( "Return is not supported for the fail point \" {}\" " , $name) ;
798798 } ) ;
799799 } } ;
800+ ( $name: expr, | $arg: ident $( : $t: ty ) ? | async $block: tt ) => { {
801+ if let Some ( res) = $crate:: eval( $name, { | $arg $( : $t) ?| async $block} ) {
802+ return res. await ;
803+ }
804+ } } ;
800805 ( $name: expr, $e: expr) => { {
801806 if let Some ( res) = $crate:: eval( $name, $e) {
802807 return res;
Original file line number Diff line number Diff line change @@ -36,6 +36,24 @@ fn test_return() {
3636 assert_eq ! ( f( ) , 2 ) ;
3737}
3838
39+ #[ tokio:: test]
40+ #[ cfg_attr( not( feature = "failpoints" ) , ignore) ]
41+ async fn test_async_return ( ) {
42+ async fn async_fn ( ) -> usize {
43+ fail_point ! ( "async_return" , |s: Option <String >| async {
44+ ( async { } ) . await ;
45+ s. map_or( 2 , |s| s. parse( ) . unwrap( ) )
46+ } ) ;
47+ 0
48+ }
49+
50+ fail:: cfg ( "async_return" , "return(1000)" ) . unwrap ( ) ;
51+ assert_eq ! ( async_fn( ) . await , 1000 ) ;
52+
53+ fail:: cfg ( "async_return" , "return" ) . unwrap ( ) ;
54+ assert_eq ! ( async_fn( ) . await , 2 ) ;
55+ }
56+
3957#[ test]
4058#[ cfg_attr( not( feature = "failpoints" ) , ignore) ]
4159fn test_sleep ( ) {
You can’t perform that action at this time.
0 commit comments