#async-test #async #safe #test-macro #testing #async-task #safina

dev safina-async-test

Macro for running async tests - ARCHIVED: Code moved to safina crate

6 releases

0.1.14 Oct 27, 2024
0.1.13 Mar 16, 2022
0.1.11 Feb 25, 2022
0.1.9 Mar 27, 2021
0.1.7 Dec 31, 2020

#1426 in Asynchronous

Download history 15/week @ 2024-08-26 3/week @ 2024-09-09 23/week @ 2024-09-23 19/week @ 2024-09-30 7/week @ 2024-10-07 3/week @ 2024-10-14 12/week @ 2024-10-21 147/week @ 2024-10-28 10/week @ 2024-11-04 13/week @ 2024-11-18 9/week @ 2024-11-25 17/week @ 2024-12-02 45/week @ 2024-12-09

84 downloads per month
Used in 5 crates

Apache-2.0

80KB
867 lines

ARCHIVED ARCHIVED ARCHIVED

This crate is archived and will not be updated.

The macro is now at safina::async_test in the safina crate.


safina-async-test

An async_test macro for running async fn tests.

It is part of safina, a safe async runtime.

Features

  • Runs tests with safina_executor
  • Each test gets its own executor with 2 threads for async tasks and 1 thread for blocking tasks.
  • Also calls safina_timer::start_timer_thread before running the test
  • forbid(unsafe_code)
  • Lightweight dependencies
  • Straightforward implementation

Limitations

Examples

use safina_async_test::async_test;

#[async_test]
async fn test1() {
    async_work().await.unwrap();
}
use safina_async_test::async_test;

// Make your test an `async fn`.
#[async_test]
async fn test2() {
    // You can `await`.
    async_work().await.unwrap();

    // You can spawn tasks which will run on
    // the executor.
    // These tasks stop when the test
    // function returns and drops the
    // executor.
    safina_executor::spawn(background_task());

    // You can run blocking code without
    // stalling other async tasks.
    let result = safina_executor::schedule_blocking(
        || blocking_work()
    ).async_recv().await.unwrap();
    assert_eq!(3, result.unwrap());

    // You can use timer functions.
    safina_timer::sleep_for(
        Duration::from_millis(10)).await;
    safina_timer::with_timeout(
        async_work(),
        Duration::from_millis(100)
    ).await.unwrap();
}

Documentation

https://docs.rs/safina-async-test

Alternatives

Changelog

  • v0.1.13 - Use safina-executor v0.3.1.
  • v0.1.12 - Use safina-executor v0.3.0.
  • v0.1.11 - Update docs.
  • v0.1.10 - Use safina-executor v0.2.0.
  • v0.1.9 - Don't require users to also depend on safina-executor and safina-timer crates.
  • v0.1.8
    • Support stable with rust 1.51 and once_cell.
    • Start an Executor for each test
  • v0.1.7 - Update to safina-executor v0.1.4
  • v0.1.6 - Start safina-timer thread
  • v0.1.5 - Use safina-executor v0.1.3 API
  • v0.1.4 - Upgrade to new safina-executor version which removes need for Box::pin.
  • v0.1.3 - Rename safina package to safina-executor.
  • v0.1.2 - Update docs
  • v0.1.1 - First published version

TO DO

Release Process

  1. Edit Cargo.toml and bump version number.
  2. Run ./release.sh

Dependencies

~360KB