summaryrefslogtreecommitdiffstats
path: root/tokio/src/time/tests
diff options
context:
space:
mode:
authorKevin Leimkuhler <kleimkuhler@icloud.com>2019-11-20 12:24:41 -0800
committerCarl Lerche <me@carllerche.com>2019-11-20 12:24:41 -0800
commit3e643c7b81736a4c2b11387a6f71aba99450270b (patch)
tree2be18c72374efcf8716c3a7d90783027231f909a /tokio/src/time/tests
parentbc150cd0b56cf6dcb7c4feab64e83b9938faa186 (diff)
time: Eagerly bind delays to timer (#1800)
## Motivation Similar to #1666, it is no longer necessary to lazily register delays with the executions default timer. All delays are expected to be created from within a runtime, and should panic if not done so. ## Solution `tokio::time` now assumes there to be a `CURRENT_TIMER` set when creating a delay; this can be assumed if called within a tokio runtime. If there is no current timer, the application will panic with a "no current timer" message. ## Follow-up Similar to #1666, `HandlePriv` can probably be removed, but this mainly prepares for 0.2 API changes. Because it is not in the public API, this can be done in a following change. Signed-off-by: Kevin Leimkuhler <kleimkuhler@icloud.com>
Diffstat (limited to 'tokio/src/time/tests')
-rw-r--r--tokio/src/time/tests/mod.rs22
-rw-r--r--tokio/src/time/tests/test_delay.rs22
2 files changed, 24 insertions, 20 deletions
diff --git a/tokio/src/time/tests/mod.rs b/tokio/src/time/tests/mod.rs
index 0aead136..6a9f25da 100644
--- a/tokio/src/time/tests/mod.rs
+++ b/tokio/src/time/tests/mod.rs
@@ -1,4 +1,24 @@
mod mock_clock;
-
mod test_delay;
mod test_queue;
+
+use crate::time::{self, Instant};
+use std::time::Duration;
+
+fn assert_send<T: Send>() {}
+fn assert_sync<T: Sync>() {}
+
+#[test]
+fn registration_is_send_and_sync() {
+ use crate::time::driver::Registration;
+
+ assert_send::<Registration>();
+ assert_sync::<Registration>();
+}
+
+#[test]
+#[should_panic]
+fn delay_is_eager() {
+ let when = Instant::now() + Duration::from_millis(100);
+ let _ = time::delay_until(when);
+}
diff --git a/tokio/src/time/tests/test_delay.rs b/tokio/src/time/tests/test_delay.rs
index 8b52e0a3..43bfe379 100644
--- a/tokio/src/time/tests/test_delay.rs
+++ b/tokio/src/time/tests/test_delay.rs
@@ -181,29 +181,13 @@ fn delayed_delay_level_1() {
}
#[test]
+#[should_panic]
fn creating_delay_outside_of_context() {
let now = Instant::now();
// This creates a delay outside of the context of a mock timer. This tests
- // that it will still expire.
- let mut fut = task::spawn(delay_until(now + ms(500)));
-
- mock(|clock| {
- // This registers the delay with the timer
- assert_pending!(fut.poll());
-
- // Wait some time... the timer is cascading
- clock.turn_for(ms(1000));
- assert_eq!(clock.advanced(), ms(448));
-
- assert_pending!(fut.poll());
-
- clock.turn_for(ms(1000));
- assert_eq!(clock.advanced(), ms(500));
-
- // The delay has elapsed
- assert_ready!(fut.poll());
- });
+ // that it will panic.
+ let _fut = task::spawn(delay_until(now + ms(500)));
}
#[test]