diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 02:53:24 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 02:53:24 +0000 |
commit | 7a9241f7a02b783b89a9fd4a6d77c5e382f7726b (patch) | |
tree | 231ddc60e333497186cc848cf56a865dddc354a0 | |
parent | 8c602f77235091f1b009bd1c2f2ad1a865cd2c74 (diff) | |
parent | 1aee49a7cb0343063e96da18214da7189c681a27 (diff) | |
download | tokio-test-android13-frc-ipsec-release.tar.gz |
Snap for 8191477 from 1aee49a7cb0343063e96da18214da7189c681a27 to tm-frc-ipsec-releaset_frc_ips_330443010android13-frc-ipsec-release
Change-Id: Ie2de577f887af26b3e333cf0c51f3310fe5cc0e9
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 109 | ||||
-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-- | TEST_MAPPING | 111 | ||||
-rw-r--r-- | cargo2android.json | 5 | ||||
-rw-r--r-- | src/macros.rs | 34 |
10 files changed, 85 insertions, 200 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" } } @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --dependencies --device --tests. +// This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. package { @@ -22,6 +22,8 @@ rust_library { name: "libtokio_test", host_supported: true, crate_name: "tokio_test", + cargo_env_compat: true, + cargo_pkg_version: "0.4.2", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -34,38 +36,10 @@ rust_library { } rust_defaults { - name: "tokio-test_defaults", - crate_name: "tokio_test", - srcs: ["src/lib.rs"], - test_suites: ["general-tests"], - auto_gen_config: true, - edition: "2018", - rustlibs: [ - "libasync_stream", - "libbytes", - "libfutures_core", - "libfutures_util", - "libtokio", - "libtokio_stream", - ], -} - -rust_test_host { - name: "tokio-test_host_test_src_lib", - defaults: ["tokio-test_defaults"], - test_options: { - unit_test: true, - }, -} - -rust_test { - name: "tokio-test_device_test_src_lib", - defaults: ["tokio-test_defaults"], -} - -rust_defaults { - name: "tokio-test_defaults_tokio_test", + name: "tokio-test_test_defaults", crate_name: "tokio_test", + cargo_env_compat: true, + cargo_pkg_version: "0.4.2", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -80,9 +54,10 @@ rust_defaults { ], } -rust_test_host { - name: "tokio-test_host_test_tests_block_on", - defaults: ["tokio-test_defaults_tokio_test"], +rust_test { + name: "tokio-test_test_tests_block_on", + defaults: ["tokio-test_test_defaults"], + host_supported: true, srcs: ["tests/block_on.rs"], test_options: { unit_test: true, @@ -90,14 +65,9 @@ rust_test_host { } rust_test { - name: "tokio-test_device_test_tests_block_on", - defaults: ["tokio-test_defaults_tokio_test"], - srcs: ["tests/block_on.rs"], -} - -rust_test_host { - name: "tokio-test_host_test_tests_io", - defaults: ["tokio-test_defaults_tokio_test"], + name: "tokio-test_test_tests_io", + defaults: ["tokio-test_test_defaults"], + host_supported: true, srcs: ["tests/io.rs"], test_options: { unit_test: true, @@ -105,58 +75,11 @@ rust_test_host { } rust_test { - name: "tokio-test_device_test_tests_io", - defaults: ["tokio-test_defaults_tokio_test"], - srcs: ["tests/io.rs"], -} - -rust_test_host { - name: "tokio-test_host_test_tests_macros", - defaults: ["tokio-test_defaults_tokio_test"], + name: "tokio-test_test_tests_macros", + defaults: ["tokio-test_test_defaults"], + host_supported: true, srcs: ["tests/macros.rs"], test_options: { unit_test: true, }, } - -rust_test { - name: "tokio-test_device_test_tests_macros", - defaults: ["tokio-test_defaults_tokio_test"], - srcs: ["tests/macros.rs"], -} - -// dependent_library ["feature_list"] -// async-stream-0.3.0 -// async-stream-impl-0.3.0 -// 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" -// instant-0.1.9 -// libc-0.2.92 "default,std" -// lock_api-0.4.2 -// log-0.4.14 -// memchr-2.3.4 "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" -// parking_lot-0.11.1 "default" -// parking_lot_core-0.8.3 -// pin-project-lite-0.2.6 -// pin-utils-0.1.0 -// proc-macro-hack-0.5.19 -// proc-macro-nested-0.1.7 -// proc-macro2-1.0.26 "default,proc-macro" -// quote-1.0.9 "default,proc-macro" -// scopeguard-1.1.0 -// signal-hook-registry-1.3.0 -// slab-0.4.2 -// 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" 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/TEST_MAPPING b/TEST_MAPPING index 73ad094..f2e3379 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,113 +1,30 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { - "presubmit": [ - { - "name": "tokio-test_device_test_src_lib" - }, - { - "name": "tokio-test_device_test_tests_block_on" - }, - { - "name": "tokio-test_device_test_tests_io" - }, - { - "name": "tokio-test_device_test_tests_macros" - }, - { - "name": "tokio_device_test_tests_buffered" - }, - { - "name": "tokio_device_test_tests_io_async_read" - }, - { - "name": "tokio_device_test_tests_io_copy_bidirectional" - }, - { - "name": "tokio_device_test_tests_io_lines" - }, - { - "name": "tokio_device_test_tests_io_mem_stream" - }, - { - "name": "tokio_device_test_tests_io_read" - }, - { - "name": "tokio_device_test_tests_io_read_buf" - }, - { - "name": "tokio_device_test_tests_io_read_to_end" - }, - { - "name": "tokio_device_test_tests_io_take" - }, - { - "name": "tokio_device_test_tests_io_write" - }, - { - "name": "tokio_device_test_tests_io_write_all" - }, - { - "name": "tokio_device_test_tests_io_write_buf" - }, - { - "name": "tokio_device_test_tests_io_write_int" - }, - { - "name": "tokio_device_test_tests_macros_join" - }, - { - "name": "tokio_device_test_tests_no_rt" - }, - { - "name": "tokio_device_test_tests_rt_basic" - }, - { - "name": "tokio_device_test_tests_rt_threaded" - }, - { - "name": "tokio_device_test_tests_sync_barrier" - }, - { - "name": "tokio_device_test_tests_sync_broadcast" - }, - { - "name": "tokio_device_test_tests_sync_errors" - }, - { - "name": "tokio_device_test_tests_sync_mpsc" - }, - { - "name": "tokio_device_test_tests_sync_mutex_owned" - }, - { - "name": "tokio_device_test_tests_sync_rwlock" - }, - { - "name": "tokio_device_test_tests_sync_watch" - }, - { - "name": "tokio_device_test_tests_task_local" - }, + "imports": [ { - "name": "tokio_device_test_tests_task_local_set" - }, + "path": "external/rust/crates/tokio" + } + ], + "presubmit": [ { - "name": "tokio_device_test_tests_tcp_accept" + "name": "tokio-test_test_tests_block_on" }, { - "name": "tokio_device_test_tests_tcp_echo" + "name": "tokio-test_test_tests_io" }, { - "name": "tokio_device_test_tests_tcp_into_std" - }, + "name": "tokio-test_test_tests_macros" + } + ], + "presubmit-rust": [ { - "name": "tokio_device_test_tests_tcp_shutdown" + "name": "tokio-test_test_tests_block_on" }, { - "name": "tokio_device_test_tests_time_rt" + "name": "tokio-test_test_tests_io" }, { - "name": "tokio_device_test_tests_uds_split" + "name": "tokio-test_test_tests_macros" } ] } diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..d36fb44 --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,5 @@ +{ + "device": true, + "run": true, + "tests": true +}
\ No newline at end of file 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 + ); + }}; +} |