5 个版本
0.1.13 | 2022年3月16日 |
---|---|
0.1.12 | 2022年3月15日 |
0.1.11 | 2022年2月25日 |
0.1.9 | 2021年3月27日 |
0.1.7 |
|
#1699 在 异步
每月37次下载
在 5 crate 中使用
81KB
867 行
saifina-async-test
用于运行 async fn
测试的 async_test
宏。
它是 safina
的一部分,一个安全的异步运行时。
特性
- 使用
safina_executor
运行测试 - 每个测试都有自己的 executor,包含 2 个线程用于异步任务和 1 个线程用于阻塞任务。
- 在运行测试之前还调用了
safina_timer::start_timer_thread
禁止(不安全代码)
- 轻量级依赖
- 直接实现
限制
- 在
stable
上构建需要包含一些不安全代码的once_cell
crate。这是必要的,直到std::lazy::OnceCell
稳定。
示例
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();
}
文档
https://docs.rs/safina-async-test
替代方案
变更日志
- v0.1.13 - 使用
safina-executor
v0.3.1。 - v0.1.12 - 使用
safina-executor
v0.3.0。 - v0.1.11 - 更新文档。
- v0.1.10 - 使用
safina-executor
v0.2.0。 - v0.1.9 - 不需要用户也依赖
safina-executor
和safina-timer
crate。 - v0.1.8
- 支持稳定版 rust 1.51 和
once_cell
。 - 为每个测试启动 Executor
- 支持稳定版 rust 1.51 和
- v0.1.7 - 更新到 safina-executor v0.1.4
- 版本 v0.1.6 - 开始
safina-timer
线程 - 版本 v0.1.5 - 使用
safina-executor
v0.1.3 API - 版本 v0.1.4 - 升级到新的
safina-executor
版本,该版本删除了需要Box::pin
的需求。 - 版本 v0.1.3 - 将
safina
包重命名为safina-executor
。 - 版本 v0.1.2 - 更新文档
- 版本 v0.1.1 - 首次发布版本
待办事项
发布流程
- 编辑
Cargo.toml
并增加版本号。 - 运行
./release.sh
许可证:Apache-2.0
依赖项
~360KB