示例
tokio 1.53.1: Make tokio timer code deterministic and instant in tests with a paused clock, driving sleep, timeout, interval and select! on virtual time from a hand-built runtime rather than #[tokio::test]
已验证示例 — cargo tokio 1.53.1: Make tokio timer code deterministic and instant in tests with a paused clock, driving sleep, timeout, interval and select! on…
sha256:bcc9f63d5a6beb65a8a582a8dcb9de5d559b3aa848d5a70a231e9c0e7d6ee136
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 2
声明的环境
rust 1 linux x64 rust 1 rust cargo
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-14 |
| rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-18 |
案例
HOW- 目标
- Make tokio timer code deterministic and instant in tests with a paused clock, driving sleep, timeout, interval and select! on virtual time from a hand-built runtime rather than #[tokio::test]
- 符号
-
- tokio::runtime::Builder::start_paused
- tokio::runtime::Builder::enable_time
- tokio::time::sleep
- tokio::time::timeout
- tokio::time::interval
- tokio::time::advance
- tokio::time::Instant
- tokio::select
- 环境
- rust 1
- 创建时间
- 2026-08-14T12:58:22Z
契约
- assert a one hour sleep under a paused clock advances tokio::time::Instant by exactly one hour
- assert that hour of virtual time costs under 250 milliseconds of real time
- assert timeout on a future that never completes returns Err(Elapsed) whose Display is "deadline has elapsed"
- assert the clock stops exactly on the timeout deadline rather than somewhere past it
- assert a fresh Interval already has one tick due before anything awaits it
- assert taking that first tick costs zero virtual time
- assert advance() past five periods makes five ticks due at once under the default MissedTickBehavior::Burst
- assert the clock sits exactly 300 virtual seconds on from the interval's creation after that advance
- assert four ticks of a 60 second interval take 180 seconds of virtual time, not 240
- assert select! with a timeout branch picks the timeout when the other branch can never resolve
- assert the clock lands exactly on that select! timeout deadline
- assert two select! branches one millisecond apart resolve to the shorter one 100 times in a row
- assert those 100 races cost exactly one second of virtual time in total
- assert the whole run adds up to exactly 4116 seconds of virtual time
- assert 4116 seconds of virtual time pass in under a second of real time
- assert start_paused without enable_time still builds, then panics on the first sleep with the message naming enable_time
- assert a Sleep constructed outside the runtime instead panics that no reactor is running, even when that runtime has its time driver enabled
- assert start_paused on a multi_thread runtime panics inside build() with the message naming the current_thread runtime, instead of returning Err
文件
- Cargo.lock
- Cargo.toml
- csx.json
- src/main.rs