9 releases

0.3.3 Feb 19, 2024
0.3.2 Feb 19, 2024
0.3.1 Jun 1, 2022
0.2.2 Jun 1, 2022
0.1.1 Mar 30, 2022

#1592 in Asynchronous

Download history 360/week @ 2023-12-22 289/week @ 2023-12-29 879/week @ 2024-01-05 820/week @ 2024-01-12 465/week @ 2024-01-19 877/week @ 2024-01-26 388/week @ 2024-02-02 1646/week @ 2024-02-09 2613/week @ 2024-02-16 1310/week @ 2024-02-23 1339/week @ 2024-03-01 1800/week @ 2024-03-08 2014/week @ 2024-03-15 1191/week @ 2024-03-22 986/week @ 2024-03-29 1609/week @ 2024-04-05

6,054 downloads per month
Used in openraft

MIT license

26KB
463 lines

async-entry

Entry macro for tokio based async test.

It does the same as #[tokio::test], with two additional feature:

  • Wrap a testing fn with a span with tracing_span="<log_level>".

  • Add an initializing statement with init="<expr>". The value returned from the initializing expr will be held until test quit. Thus, it can be used to initialize logging or else.

#[async_entry::test(init="g()", tracing_span="info")]
async fn foo() {
    assert!(true);
}
// Will build a test fn:
// #[test]
// fn foo() {
//     let _g = g();
//     let body = async {
//         assert!(true);
//     };
//     use tracing::Instrument;
//     let body = body.instrument(tracing::info_span("foo");
//     let rt = tokio::runtime::Builder::new_current_thread()
//         .enable_all()
//         .build()
//         .expect("Failed building the Runtime");
//     #[allow(clippy::expect_used)]
//     rt.block_on(body);
// }

Development

Test

Run test.sh to check the expanded macro and compile them.

Dependencies

~1.5MB
~34K SLoC