tests: reduce sleep durations (#3994)

This commit is contained in:
Alice Ryhl
2021-07-30 11:27:04 +02:00
committed by GitHub
parent f51676891f
commit 0d9430b99c
9 changed files with 44 additions and 35 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ async fn block_write(s: &mut TcpStream) -> usize {
result = s.write(&BUF) => {
copied += result.expect("write error")
},
_ = tokio::time::sleep(Duration::from_millis(100)) => {
_ = tokio::time::sleep(Duration::from_millis(10)) => {
break;
}
}
+16 -5
View File
@@ -360,7 +360,21 @@ async fn use_future_in_if_condition() {
use tokio::time::{self, Duration};
tokio::select! {
_ = time::sleep(Duration::from_millis(50)), if false => {
_ = time::sleep(Duration::from_millis(10)), if false => {
panic!("if condition ignored")
}
_ = async { 1u32 } => {
}
}
}
#[tokio::test]
async fn use_future_in_if_condition_biased() {
use tokio::time::{self, Duration};
tokio::select! {
biased;
_ = time::sleep(Duration::from_millis(10)), if false => {
panic!("if condition ignored")
}
_ = async { 1u32 } => {
@@ -456,10 +470,7 @@ async fn require_mutable(_: &mut i32) {}
async fn async_noop() {}
async fn async_never() -> ! {
use tokio::time::Duration;
loop {
tokio::time::sleep(Duration::from_millis(10)).await;
}
futures::future::pending().await
}
// From https://github.com/tokio-rs/tokio/issues/2857
+2 -2
View File
@@ -126,7 +126,7 @@ async fn test_named_pipe_multi_client() -> io::Result<()> {
}
// Wait for a named pipe to become available.
time::sleep(Duration::from_millis(50)).await;
time::sleep(Duration::from_millis(10)).await;
};
let mut client = BufReader::new(client);
@@ -255,7 +255,7 @@ async fn test_named_pipe_multi_client_ready() -> io::Result<()> {
}
// Wait for a named pipe to become available.
time::sleep(Duration::from_millis(50)).await;
time::sleep(Duration::from_millis(10)).await;
};
let mut read_buf = [0u8; 5];
+1 -1
View File
@@ -26,7 +26,7 @@ fn panics_when_no_reactor() {
async fn timeout_value() {
let (_tx, rx) = oneshot::channel::<()>();
let dur = Duration::from_millis(20);
let dur = Duration::from_millis(10);
let _ = timeout(dur, rx).await;
}
+12 -12
View File
@@ -3,7 +3,7 @@
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
use tokio::time::Duration;
use tokio::runtime::Builder;
@@ -28,11 +28,11 @@ fn test_abort_without_panic_3157() {
rt.block_on(async move {
let handle = tokio::spawn(async move {
println!("task started");
tokio::time::sleep(std::time::Duration::new(100, 0)).await
tokio::time::sleep(Duration::new(100, 0)).await
});
// wait for task to sleep.
tokio::time::sleep(std::time::Duration::new(1, 0)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
handle.abort();
let _ = handle.await;
@@ -138,7 +138,7 @@ fn remote_abort_local_set_3929() {
});
let jh2 = std::thread::spawn(move || {
sleep(Duration::from_millis(50));
sleep(Duration::from_millis(10));
jh.abort();
});
@@ -160,17 +160,17 @@ fn test_abort_wakes_task_3964() {
// Make sure the Arc is moved into the task
let _notify_dropped = notify_dropped;
println!("task started");
tokio::time::sleep(std::time::Duration::new(100, 0)).await
tokio::time::sleep(Duration::new(100, 0)).await
});
// wait for task to sleep.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
handle.abort();
drop(handle);
// wait for task to abort.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
// Check that the Arc has been dropped.
assert!(weak_notify_dropped.upgrade().is_none());
@@ -188,17 +188,17 @@ fn test_abort_task_that_panics_on_drop_contained() {
// Make sure the Arc is moved into the task
let _panic_dropped = PanicOnDrop;
println!("task started");
tokio::time::sleep(std::time::Duration::new(100, 0)).await
tokio::time::sleep(Duration::new(100, 0)).await
});
// wait for task to sleep.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
handle.abort();
drop(handle);
// wait for task to abort.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
});
}
@@ -212,11 +212,11 @@ fn test_abort_task_that_panics_on_drop_returned() {
// Make sure the Arc is moved into the task
let _panic_dropped = PanicOnDrop;
println!("task started");
tokio::time::sleep(std::time::Duration::new(100, 0)).await
tokio::time::sleep(Duration::new(100, 0)).await
});
// wait for task to sleep.
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
tokio::time::sleep(Duration::from_millis(10)).await;
handle.abort();
assert!(handle.await.unwrap_err().is_panic());
+6 -8
View File
@@ -67,11 +67,11 @@ async fn localset_future_timers() {
let local = LocalSet::new();
local.spawn_local(async move {
time::sleep(Duration::from_millis(10)).await;
time::sleep(Duration::from_millis(5)).await;
RAN1.store(true, Ordering::SeqCst);
});
local.spawn_local(async move {
time::sleep(Duration::from_millis(20)).await;
time::sleep(Duration::from_millis(10)).await;
RAN2.store(true, Ordering::SeqCst);
});
local.await;
@@ -299,9 +299,7 @@ fn drop_cancels_tasks() {
let _rc2 = rc2;
started_tx.send(()).unwrap();
loop {
time::sleep(Duration::from_secs(3600)).await;
}
futures::future::pending::<()>().await;
});
local.block_on(&rt, async {
@@ -416,7 +414,7 @@ async fn local_tasks_are_polled_after_tick() {
.run_until(async {
let task2 = task::spawn(async move {
// Wait a bit
time::sleep(Duration::from_millis(100)).await;
time::sleep(Duration::from_millis(10)).await;
let mut oneshots = Vec::with_capacity(EXPECTED);
@@ -427,13 +425,13 @@ async fn local_tasks_are_polled_after_tick() {
tx.send(oneshot_rx).unwrap();
}
time::sleep(Duration::from_millis(100)).await;
time::sleep(Duration::from_millis(10)).await;
for tx in oneshots.drain(..) {
tx.send(()).unwrap();
}
time::sleep(Duration::from_millis(300)).await;
time::sleep(Duration::from_millis(10)).await;
let rx1 = RX1.load(SeqCst);
let rx2 = RX2.load(SeqCst);
println!("EXPECT = {}; RX1 = {}; RX2 = {}", EXPECTED, rx1, rx2);
+1 -1
View File
@@ -116,7 +116,7 @@ async fn drop_write() -> Result<()> {
// drop it while the read is in progress
std::thread::spawn(move || {
thread::sleep(std::time::Duration::from_millis(50));
thread::sleep(std::time::Duration::from_millis(10));
drop(write_half);
});
+4 -4
View File
@@ -13,7 +13,7 @@ fn timer_with_threaded_runtime() {
let (tx, rx) = mpsc::channel();
rt.spawn(async move {
let when = Instant::now() + Duration::from_millis(100);
let when = Instant::now() + Duration::from_millis(10);
sleep_until(when).await;
assert!(Instant::now() >= when);
@@ -32,7 +32,7 @@ fn timer_with_basic_scheduler() {
let (tx, rx) = mpsc::channel();
rt.block_on(async move {
let when = Instant::now() + Duration::from_millis(100);
let when = Instant::now() + Duration::from_millis(10);
sleep_until(when).await;
assert!(Instant::now() >= when);
@@ -67,7 +67,7 @@ async fn starving() {
}
}
let when = Instant::now() + Duration::from_millis(20);
let when = Instant::now() + Duration::from_millis(10);
let starve = Starve(Box::pin(sleep_until(when)), 0);
starve.await;
@@ -81,7 +81,7 @@ async fn timeout_value() {
let (_tx, rx) = oneshot::channel::<()>();
let now = Instant::now();
let dur = Duration::from_millis(20);
let dur = Duration::from_millis(10);
let res = timeout(dur, rx).await;
assert!(res.is_err());
+1 -1
View File
@@ -24,7 +24,7 @@ async fn immediate_sleep() {
async fn is_elapsed() {
time::pause();
let sleep = time::sleep(Duration::from_millis(50));
let sleep = time::sleep(Duration::from_millis(10));
tokio::pin!(sleep);