diff options
author | Joel Galenson <jgalenson@google.com> | 2021-05-26 19:40:42 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-05-26 19:40:42 +0000 |
commit | d7a0e8ad625499ef67b57cfd0438a19abbdbc5b8 (patch) | |
tree | 7c9ea86b04094bc8e43b6dad60e99fd8a2c96f65 | |
parent | 1566b996d39d2bb914e63ee86ee6a619d4208499 (diff) | |
parent | f51066b84ee1f377743ffa07359d5c9dee603325 (diff) | |
download | tokio-test-d7a0e8ad625499ef67b57cfd0438a19abbdbc5b8.tar.gz |
Upgrade rust/crates/tokio-test to 0.4.2 am: 061ddcc8ef am: f51066b84e
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/tokio-test/+/1713269
Change-Id: I3d0a713aa84be8582b033d59d2c131613dc5a739
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 30 | ||||
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | src/macros.rs | 34 |
8 files changed, 65 insertions, 25 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 9388b50..eb7e2b0 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "e40ec3e4243f95b39a42bcc9049551b62c3058a0" + "sha1": "ff9b0ef7ca5a93f8fb10baba52996e755500546f" } } @@ -126,20 +126,20 @@ rust_test { } // dependent_library ["feature_list"] -// async-stream-0.3.0 -// async-stream-impl-0.3.0 +// async-stream-0.3.1 +// async-stream-impl-0.3.1 // autocfg-1.0.1 // bytes-1.0.1 "default,std" // cfg-if-1.0.0 -// futures-core-0.3.13 "alloc,default,std" -// futures-macro-0.3.13 -// futures-task-0.3.13 "alloc,std" -// futures-util-0.3.13 "alloc,async-await,async-await-macro,default,futures-macro,proc-macro-hack,proc-macro-nested,slab,std" +// futures-core-0.3.15 "alloc,default,std" +// futures-macro-0.3.15 +// futures-task-0.3.15 "alloc,std" +// futures-util-0.3.15 "alloc,async-await,async-await-macro,default,futures-macro,proc-macro-hack,proc-macro-nested,slab,std" // instant-0.1.9 -// libc-0.2.92 "default,std" -// lock_api-0.4.2 +// libc-0.2.94 "default,std" +// lock_api-0.4.4 // log-0.4.14 -// memchr-2.3.4 "default,std" +// memchr-2.4.0 "default,std" // mio-0.7.11 "default,net,os-ext,os-poll,os-util,tcp,udp,uds" // num_cpus-1.13.0 // once_cell-1.7.2 "alloc,default,race,std" @@ -153,10 +153,10 @@ rust_test { // quote-1.0.9 "default,proc-macro" // scopeguard-1.1.0 // signal-hook-registry-1.3.0 -// slab-0.4.2 +// slab-0.4.3 "default,std" // smallvec-1.6.1 -// syn-1.0.68 "clone-impls,default,derive,extra-traits,full,parsing,printing,proc-macro,quote,visit-mut" -// tokio-1.4.0 "bytes,default,fs,full,io-std,io-util,libc,macros,memchr,mio,net,num_cpus,once_cell,parking_lot,process,rt,rt-multi-thread,signal,signal-hook-registry,sync,test-util,time,tokio-macros,winapi" -// tokio-macros-1.1.0 -// tokio-stream-0.1.5 "default,time" -// unicode-xid-0.2.1 "default" +// syn-1.0.72 "clone-impls,default,derive,extra-traits,full,parsing,printing,proc-macro,quote,visit-mut" +// tokio-1.6.0 "bytes,default,fs,full,io-std,io-util,libc,macros,memchr,mio,net,num_cpus,once_cell,parking_lot,process,rt,rt-multi-thread,signal,signal-hook-registry,sync,test-util,time,tokio-macros,winapi" +// tokio-macros-1.2.0 +// tokio-stream-0.1.6 "default,time" +// unicode-xid-0.2.2 "default" diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fba3ce..5b1786f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.4.2 (May 14, 2021) + +- test: add `assert_elapsed!` macro ([#3728]) + +[#3728]: https://github.com/tokio-rs/tokio/pull/3728 + # 0.4.1 (March 10, 2021) - Fix `io::Mock` to be `Send` and `Sync` ([#3594]) @@ -13,11 +13,11 @@ [package] edition = "2018" name = "tokio-test" -version = "0.4.1" +version = "0.4.2" authors = ["Tokio Contributors <team@tokio.rs>"] description = "Testing utilities for Tokio- and futures-based code\n" homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-test/0.4.1/tokio_test" +documentation = "https://docs.rs/tokio-test/0.4.2/tokio_test" categories = ["asynchronous", "testing"] license = "MIT" repository = "https://github.com/tokio-rs/tokio" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 2691c89..55d5aaf 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -6,13 +6,13 @@ name = "tokio-test" # - Cargo.toml # - Update CHANGELOG.md. # - Create "tokio-test-0.4.x" git tag. -version = "0.4.1" +version = "0.4.2" edition = "2018" authors = ["Tokio Contributors <team@tokio.rs>"] license = "MIT" repository = "https://github.com/tokio-rs/tokio" homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-test/0.4.1/tokio_test" +documentation = "https://docs.rs/tokio-test/0.4.2/tokio_test" description = """ Testing utilities for Tokio- and futures-based code """ @@ -1,4 +1,4 @@ -Copyright (c) 2020 Tokio Contributors +Copyright (c) 2021 Tokio Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/tokio-test/tokio-test-0.4.1.crate" + value: "https://static.crates.io/crates/tokio-test/tokio-test-0.4.2.crate" } - version: "0.4.1" + version: "0.4.2" license_type: NOTICE last_upgrade_date { year: 2021 - month: 4 - day: 2 + month: 5 + day: 19 } } diff --git a/src/macros.rs b/src/macros.rs index 299bd77..7ca7345 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -259,3 +259,37 @@ macro_rules! assert_err { } }}; } + +/// Asserts that an exact duration has elapsed since since the start instant ±1ms. +/// +/// ```rust +/// use tokio::time::{self, Instant}; +/// use std::time::Duration; +/// use tokio_test::assert_elapsed; +/// # async fn test_time_passed() { +/// +/// let start = Instant::now(); +/// let dur = Duration::from_millis(50); +/// time::sleep(dur).await; +/// assert_elapsed!(start, dur); +/// # } +/// ``` +/// +/// This 1ms buffer is required because Tokio's hashed-wheel timer has finite time resolution and +/// will not always sleep for the exact interval. +#[macro_export] +macro_rules! assert_elapsed { + ($start:expr, $dur:expr) => {{ + let elapsed = $start.elapsed(); + // type ascription improves compiler error when wrong type is passed + let lower: std::time::Duration = $dur; + + // Handles ms rounding + assert!( + elapsed >= lower && elapsed <= lower + std::time::Duration::from_millis(1), + "actual = {:?}, expected = {:?}", + elapsed, + lower + ); + }}; +} |