summaryrefslogtreecommitdiffstats
path: root/tokio-test
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-10-21 16:45:13 -0700
committerGitHub <noreply@github.com>2019-10-21 16:45:13 -0700
commitb8cee1a60ad99ef28ec494ae4230e2ef4399fcf9 (patch)
tree5bde8f840d2450397beb3403141802f558ff1147 /tokio-test
parentc9bcbe77b9fa36868cc94cc75426823c7ec205ac (diff)
timer: move `tokio-timer` into `tokio` crate (#1674)
A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The `timer` implementation is now provided by the main `tokio` crate. The `timer` functionality may still be excluded from the build by skipping the `timer` feature flag.
Diffstat (limited to 'tokio-test')
-rw-r--r--tokio-test/Cargo.toml1
-rw-r--r--tokio-test/src/clock.rs12
-rw-r--r--tokio-test/src/io.rs46
-rw-r--r--tokio-test/tests/block_on.rs5
-rw-r--r--tokio-test/tests/clock.rs34
5 files changed, 22 insertions, 76 deletions
diff --git a/tokio-test/Cargo.toml b/tokio-test/Cargo.toml
index 2c5fbf4b..ce9ece11 100644
--- a/tokio-test/Cargo.toml
+++ b/tokio-test/Cargo.toml
@@ -24,7 +24,6 @@ tokio = { version = "=0.2.0-alpha.6", path = "../tokio" }
tokio-executor = { version = "=0.2.0-alpha.6", path = "../tokio-executor" }
tokio-io = { version = "=0.2.0-alpha.6", path = "../tokio-io" }
tokio-sync = { version = "=0.2.0-alpha.6", path = "../tokio-sync" }
-tokio-timer = { version = "=0.3.0-alpha.6", path = "../tokio-timer" }
futures-core-preview = "=0.3.0-alpha.19"
pin-convert = "0.1.0"
diff --git a/tokio-test/src/clock.rs b/tokio-test/src/clock.rs
index ea4f0465..dd09a009 100644
--- a/tokio-test/src/clock.rs
+++ b/tokio-test/src/clock.rs
@@ -1,11 +1,11 @@
-//! A mocked clock for use with `tokio_timer` based futures.
+//! A mocked clock for use with `tokio::timer` based futures.
//!
//! # Example
//!
//! ```
//! use tokio::clock;
+//! use tokio::timer::delay;
//! use tokio_test::{assert_ready, assert_pending, task};
-//! use tokio_timer::delay;
//!
//! use std::time::Duration;
//!
@@ -22,9 +22,9 @@
//! });
//! ```
+use tokio::timer::clock::{Clock, Now};
+use tokio::timer::Timer;
use tokio_executor::park::{Park, Unpark};
-use tokio_timer::clock::{Clock, Now};
-use tokio_timer::Timer;
use std::marker::PhantomData;
use std::rc::Rc;
@@ -125,13 +125,13 @@ impl MockClock {
where
F: FnOnce(&mut Handle) -> R,
{
- ::tokio_timer::clock::with_default(&self.clock, || {
+ tokio::timer::clock::with_default(&self.clock, || {
let park = self.time.mock_park();
let timer = Timer::new(park);
let handle = timer.handle();
let time = self.time.clone();
- let _timer = ::tokio_timer::set_default(&handle);
+ let _timer = tokio::timer::set_default(&handle);
let mut handle = Handle::new(timer, time);
f(&mut handle)
// lazy(|| Ok::<_, ()>(f(&mut handle))).wait().unwrap()
diff --git a/tokio-test/src/io.rs b/tokio-test/src/io.rs
index ffbb07c5..6610c1db 100644
--- a/tokio-test/src/io.rs
+++ b/tokio-test/src/io.rs
@@ -16,6 +16,11 @@
//! [`AsyncRead`]: tokio_io::AsyncRead
//! [`AsyncWrite`]: tokio_io::AsyncWrite
+use tokio::timer::{clock, timer, Delay};
+use tokio_io::{AsyncRead, AsyncWrite, Buf};
+use tokio_sync::mpsc;
+
+use futures_core::ready;
use std::collections::VecDeque;
use std::future::Future;
use std::pin::Pin;
@@ -23,11 +28,6 @@ use std::task::{self, Poll, Waker};
use std::time::{Duration, Instant};
use std::{cmp, io};
-use futures_core::ready;
-use tokio_io::{AsyncRead, AsyncWrite, Buf};
-use tokio_sync::mpsc;
-use tokio_timer::{clock, timer, Delay};
-
/// An I/O object that follows a predefined script.
///
/// This value is created by `Builder` and implements `AsyncRead` + `AsyncWrite`. It
@@ -268,42 +268,6 @@ impl Inner {
}
}
-/*
-impl io::Read for Mock {
- fn read(&mut self, dst: &mut [u8]) -> io::Result<usize> {
- if self.is_async() {
- tokio::async_read(self, dst)
- } else {
- self.sync_read(dst)
- }
- }
-}
-
-impl io::Write for Mock {
- fn write(&mut self, src: &[u8]) -> io::Result<usize> {
- if self.is_async() {
- tokio::async_write(self, src)
- } else {
- self.sync_write(src)
- }
- }
-
- fn flush(&mut self) -> io::Result<()> {
- Ok(())
- }
-}
-*/
-
-/*
-use self::futures::{Future, Stream, Poll, Async};
-use self::futures::sync::mpsc;
-use self::futures::task::{self, Task};
-use self::tokio_io::{AsyncRead, AsyncWrite};
-use self::tokio_timer::{Timer, Sleep};
-
-use std::io;
-*/
-
// ===== impl Inner =====
impl Mock {
diff --git a/tokio-test/tests/block_on.rs b/tokio-test/tests/block_on.rs
index 9b4959e9..6d5f481a 100644
--- a/tokio-test/tests/block_on.rs
+++ b/tokio-test/tests/block_on.rs
@@ -1,8 +1,9 @@
#![warn(rust_2018_idioms)]
-use std::time::{Duration, Instant};
+use tokio::timer::delay;
use tokio_test::block_on;
-use tokio_timer::delay;
+
+use std::time::{Duration, Instant};
#[test]
fn async_block() {
diff --git a/tokio-test/tests/clock.rs b/tokio-test/tests/clock.rs
index 344c599b..abb61e23 100644
--- a/tokio-test/tests/clock.rs
+++ b/tokio-test/tests/clock.rs
@@ -1,12 +1,11 @@
-#![cfg(feature = "broken")]
#![warn(rust_2018_idioms)]
-use futures::Future;
-use std::time::{Duration, Instant};
+use tokio::timer::delay;
use tokio_test::clock::MockClock;
-use tokio_test::task::MockTask;
-use tokio_test::{assert_not_ready, assert_ready};
-use tokio_timer::delay;
+use tokio_test::task;
+use tokio_test::{assert_pending, assert_ready};
+
+use std::time::{Duration, Instant};
#[test]
fn clock() {
@@ -14,30 +13,13 @@ fn clock() {
mock.enter(|handle| {
let deadline = Instant::now() + Duration::from_secs(1);
- let mut delay = delay(deadline);
+ let mut delay = task::spawn(delay(deadline));
- assert_not_ready!(delay.poll());
+ assert_pending!(delay.poll());
handle.advance(Duration::from_secs(2));
- assert_ready!(delay.poll());
- });
-}
-
-#[test]
-fn notify() {
- let deadline = Instant::now() + Duration::from_secs(1);
- let mut mock = MockClock::new();
- let mut task = MockTask::new();
-
- mock.enter(|handle| {
- let mut delay = delay(deadline);
-
- task.enter(|| assert_not_ready!(delay.poll()));
-
- handle.advance(Duration::from_secs(1));
-
- assert!(task.is_notified());
+ assert!(delay.is_woken());
assert_ready!(delay.poll());
});
}