id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/tests/rt_common.rs:31 | use std::task::Poll::Ready;
use tokio::sync::mpsc;
let rt = rt();
rt.block_on(async {
let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}
poll_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:32 | tokio::task::unconstrained(poll_fn(|cx| {
// All the responses should be ready.
for _ in 0..1_000 {
assert_eq!(recv.poll_recv(cx), Poll::Ready(Some(())));
}
Ready(())
})).await;
});
}
#[cfg(tokio_unstable)]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:33 | fn ping_pong_saturation() {
use std::sync::atomic::{Ordering, AtomicBool};
use tokio::sync::mpsc;
const NUM: usize = 100;
let rt = rt();
let running = Arc::new(AtomicBool::new(true));
rt.block_on(async {
let (spawned_tx, mut spawned_rx) = mpsc::unbounded_c... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:34 | }
for _ in 0..NUM {
spawned_rx.recv().await.unwrap();
}
// spawn another task and wait for it to complete
let handle = task::spawn(async {
for _ in 0..5 {
// Yielding forces it back into the local queue.
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:35 | rt.block_on(async { tokio::task::yield_now().await });
let th = std::thread::spawn(move || {
tx.send(()).unwrap();
for tx in txs.drain(..) {
let _ = tx.send(());
}
});
rx.recv().unwrap();
drop(rt);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:36 | fn drop(&mut self) {
if self.by_ref {
self.waker.take().unwrap().wake_by_ref();
} else {
self.waker.take().unwrap().wake();
}
let _ = self.done.send(true);
}
}
std::thread_local! {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common.rs | 1,401 | 1,438 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![allow(clippy::needless_range_loop)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(not(miri))]
// Tests to run on both current-thread & multi-thread runtime variants.
macro_rules! rt_test {
($($t:tt)*) => {
mod current_thread_scheduler {
$($t)*
#[cfg(not(target_os=... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
mod threaded_scheduler_1_thread {
$($t)*
const NUM_WORKERS: usize = 1;
fn rt() -> Arc<Runtime> {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | fn rt() -> Arc<Runtime> {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.enable_all()
.build()
.unwrap()
.into()
}
}
}
}
#[test]
fn send_sync_bound() {
use to... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | use std::sync::Arc;
use std::task::{Context, Poll};
#[cfg(not(target_os="wasi"))]
use std::thread;
use std::time::{Duration, Instant};
#[test]
fn block_on_sync() {
let rt = rt();
let mut win = false;
rt.block_on(async {
win = true;
});
asse... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | fn spawn_one_bg() {
let rt = rt();
let out = rt.block_on(async {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
tx.send("ZOMG").unwrap();
});
assert_ok!(rx.await)
});
assert_eq!(out, "ZOMG");
}
#[t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | fn spawn_two() {
let rt = rt();
let out = rt.block_on(async {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
tokio::spawn(async move {
assert_ok!(tx1.send("ZOMG"));
});
tokio::spawn(async move {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | let msg = assert_ok!(rx.await);
assert_eq!(i, msg);
assert_ok!(done_tx.send(msg));
});
tx
})
.collect::<Vec<_>>();
drop(done_tx);
thread::spawn(move || {
for... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | let rt = rt();
let out = rt.block_on(async {
tokio::spawn(async move {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (tx, rx) = oneshot::channel();
l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | for i in 0..ITER {
assert_eq!(i, out[i]);
}
}
#[test]
fn spawn_one_from_block_on_called_on_handle() {
let rt = rt();
let (tx, rx) = oneshot::channel();
#[allow(clippy::async_yields_async)]
let handle = rt.handle().block_on(async {
tokio::spaw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | }).await)
});
assert_eq!(out, "hello");
}
#[test]
fn outstanding_tasks_dropped() {
let rt = rt();
let cnt = Arc::new(());
rt.block_on(async {
let cnt = cnt.clone();
tokio::spawn(poll_fn(move |_| {
assert_eq!(2, Arc::strong_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | let rt2 = rt1.block_on(async { rt() });
let out = rt2.block_on(async { "ZOMG" });
assert_eq!(out, "ZOMG");
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn complete_block_on_under_load() {
let rt = rt();
rt.block_on(async {
let (t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx1.send(()));
});
tokio::spawn(async move {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | #[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn spawn_from_other_thread_under_load() {
let rt = rt();
let handle = rt.clone();
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
handle.spawn(async move {
assert_ok!(t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | #[test]
fn sleep_in_spawn() {
let rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
time::sleep(dur).await;
assert_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | rx.await.unwrap();
});
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn spawn_from_blocking() {
let rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spawn_blocking(|| {
tokio::spawn(async mo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | rt.block_on(async move {
assert_ok!(tokio::task::spawn_blocking(|| {
let now = std::time::Instant::now();
let dur = Duration::from_millis(1);
// use the futures' block_on fn to make sure we aren't setting
// any Tokio context
f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | }
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn always_active_parker() {
// This test it to show that we will always have
// an active parker even if we call block_on concurrently
let rt = rt();
let rt2 = rt.clone();
let (tx1, rx1) = one... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | //
// This test hits an edge case on windows where more threads than cores are
// created, none of those threads ever yield due to being at capacity, so
// IOCP gets "starved".
//
// For now, this is a very edge case that is probably not a real production
// concern. There also isn't a great/obv... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | let mut dst = vec![0; 11];
assert_ok!(stream.read_exact(&mut dst).await);
assert_eq!(dst, b"hello world");
});
assert_ok!(srv.await);
assert_ok!(cli.await);
});
}
/// Tests that yielded tasks are not scheduled until **after** resourc... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | #[test]
#[cfg(not(target_os="wasi"))]
#[cfg_attr(miri, ignore)] // No `socket` in miri.
fn coop_yield_defers_until_park() {
for _ in 0..10 {
if yield_defers_until_park_inner(true) {
// test passed
return;
}
// Wait a bit and run th... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | while !flag.load(SeqCst) {
std::thread::sleep(std::time::Duration::from_millis(1));
}
});
}
barrier.wait();
let (fail_test, fail_test_recv) = oneshot::channel::<()>();
let flag_clone = flag.clone();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | futures::future::pending::<()>().await;
break;
}
}
},
async {
let _ = listener.accept().await.unwrap();
flag_clone.store(true, SeqCst);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:23 | assert_ok!(rx.try_recv());
assert_err!(rx.try_recv());
}
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads or panic recovery")]
#[cfg(panic = "unwind")]
#[test]
fn panic_in_task() {
let rt = rt();
let (tx, rx) = oneshot::channel();
struct Boom(O... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 881 | 940 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | #[cfg(not(target_os="wasi"))] // Wasi does not support threads
async fn yield_once() {
let mut yielded = false;
poll_fn(|cx| {
if yielded {
Poll::Ready(())
} else {
yielded = true;
cx.waker().wake_by_ref();
Poll:... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | }
impl Drop for Never {
fn drop(&mut self) {
self.drop_tx.send(()).unwrap();
}
}
let rt = rt();
let (drop_tx, drop_rx) = mpsc::channel();
let (run_tx, run_rx) = oneshot::channel();
rt.block_on(async move {
tokio::spa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/tests/rt_common.rs:26 | let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
let barrier = Arc::new(Barrier::new(3));
let barrier1 = barrier.clone();
let barrier2 = barrier.clone();
let rt = rt();
rt.spawn(async move {
let mut tx2 = Some(tx2);
let ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/tests/rt_common.rs:27 | fn io_notify_while_shutting_down() {
use tokio::net::UdpSocket;
use std::sync::Arc;
for _ in 1..10 {
let runtime = rt();
runtime.block_on(async {
let socket = UdpSocket::bind("127.0.0.1:0").await.unwrap();
let addr = socket.local_addr().u... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:28 | runtime.block_on(async move {
task::spawn_blocking(move || {
tx.send(()).unwrap();
thread::sleep(Duration::from_secs(10_000));
});
rx.await.unwrap();
});
Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_millis(100));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:29 | // rust-lang issue in thread local storage destructors.
// See https://github.com/rust-lang/rust/issues/74875
#[test]
#[cfg(not(windows))]
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")]
fn runtime_in_thread_local() {
use std::cell::RefCell;
use std::thread;... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:30 | let mut client = TcpStream::connect(&addr).await.unwrap();
let mut buf = vec![];
client.read_to_end(&mut buf).await.unwrap();
assert_eq!(buf, b"hello");
tx.send(()).unwrap();
}
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
#[cfg_attr(miri, ignore)] // No `s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:31 | local.block_on(&rt, async move { client_server_local(tx).await });
assert_ok!(rx.try_recv());
assert_err!(rx.try_recv());
}
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
async fn client_server_local(tx: mpsc::Sender<()>) {
let server = assert_ok!(TcpListener::bind("... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:32 | let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}
poll_fn(|cx| {
// At least one response should return pending.
for _ in 0..1_000 {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:33 | Ready(())
})).await;
});
}
#[cfg(tokio_unstable)]
#[test]
fn coop_consume_budget() {
let rt = rt();
rt.block_on(async {
poll_fn(|cx| {
let counter = Arc::new(std::sync::Mutex::new(0));
let counter_clone = Arc::clone(&count... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:34 | let rt = rt();
let running = Arc::new(AtomicBool::new(true));
rt.block_on(async {
let (spawned_tx, mut spawned_rx) = mpsc::unbounded_channel();
let mut tasks = vec![];
// Spawn a bunch of tasks that ping-pong between each other to
// saturate the runtim... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:35 | // spawn another task and wait for it to complete
let handle = task::spawn(async {
for _ in 0..5 {
// Yielding forces it back into the local queue.
task::yield_now().await;
}
});
handle.await.unwrap();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:36 | }
});
rx.recv().unwrap();
drop(rt);
th.join().unwrap();
}
}
#[test]
#[cfg_attr(target_family = "wasm", ignore)]
fn wake_by_ref_from_thread_local() {
wake_from_thread_local(true);
}
#[test]
#[cfg_attr(target_family = "wasm", ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,401 | 1,460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:37 | let _ = self.done.send(true);
}
}
std::thread_local! {
static TL_DATA: RefCell<Option<TLData>> = const { RefCell::new(None) };
};
let (send, recv) = channel();
std::thread::spawn(move || {
let rt = rt();
rt.block_on(rt.spawn(poll... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 710bc8071ea030f0ad98817414997beab2420ad2 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/710bc8071ea030f0ad98817414997beab2420ad2/tokio/tests/rt_common.rs | 1,441 | 1,472 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | let mut dst = vec![0; 11];
assert_ok!(stream.read_exact(&mut dst).await);
assert_eq!(dst, b"hello world");
});
assert_ok!(srv.await);
assert_ok!(cli.await);
});
}
/// Tests that yielded tasks are not scheduled until **after** resourc... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | /// test passed.
#[cfg(not(target_os="wasi"))]
fn yield_defers_until_park_inner() -> bool {
use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
use std::sync::Barrier;
let rt = rt();
let flag = Arc::new(AtomicBool::new(false));
let barrier = Arc::new(Barrier::new(NUM... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | // Yield until connected
let mut cnt = 0;
while !flag_clone.load(SeqCst){
tokio::task::yield_now().await;
cnt += 1;
if cnt >= 10 {
// yielded too many time... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | })
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[cfg_attr(miri, ignore)] // No `socket` in miri.
#[test]
fn client_server_block_on() {
let rt = rt();
let (tx, rx) = mpsc::channel();
rt.block_on(async move { client_server(tx).await });
assert_ok... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:23 | rt.spawn(Boom(Some(tx)));
assert_ok!(rt.block_on(rx));
}
#[test]
#[should_panic]
#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")]
fn panic_in_block_on() {
let rt = rt();
rt.block_on(async { panic!() });
}
#[cfg(not(target_os="wasi"))]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 881 | 940 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | use std::sync::mpsc;
struct Never {
drop_tx: mpsc::Sender<()>,
}
impl Future for Never {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
Poll::Pending
}
}
impl Drop for Never ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | #[test]
fn wake_while_rt_is_dropping() {
use tokio::sync::Barrier;
struct OnDrop<F: FnMut()>(F);
impl<F: FnMut()> Drop for OnDrop<F> {
fn drop(&mut self) {
(self.0)()
}
}
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/tests/rt_common.rs:26 | // Wait until every oneshot channel has been polled.
rt.block_on(barrier.wait());
// Drop the rt. Regardless of which task is dropped first, its destructor will wake the
// other task.
drop(rt);
}
#[cfg(not(target_os="wasi"))] // Wasi doesn't support UDP or bind()
#[cfg_att... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/tests/rt_common.rs:27 | tokio::time::sleep(Duration::from_millis(5)).await;
});
}
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn shutdown_timeout() {
let (tx, rx) = oneshot::channel();
let runtime = rt();
runtime.block_on(async move {
task::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:28 | #[test]
fn shutdown_wakeup_time() {
let runtime = rt();
runtime.block_on(async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
});
Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_secs(10_000));
}
// This test is current... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:29 | // Get the assigned address
let addr = assert_ok!(server.local_addr());
// Spawn the server
tokio::spawn(async move {
// Accept a socket
let (mut socket, _) = server.accept().await.unwrap();
// Write some data
socket.write_all(b"hello").await.unw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:30 | rx.await.unwrap();
});
}
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
#[cfg_attr(miri, ignore)] // No `socket` in miri.
#[test]
fn local_set_client_server_block_on() {
let rt = rt();
let (tx, rx) = mpsc::channel();
let local = task::LocalSet::new();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:31 | assert_eq!(buf, b"hello");
tx.send(()).unwrap();
}
#[test]
fn coop() {
use std::task::Poll::Ready;
use tokio::sync::mpsc;
let rt = rt();
rt.block_on(async {
let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:32 | let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}
tokio::task::unconstrained(poll_fn(|cx| {
// All the responses should be ready.
for _ in 0..1_000... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:33 | });
}
// Tests that the "next task" scheduler optimization is not able to starve
// other tasks.
#[test]
fn ping_pong_saturation() {
use std::sync::atomic::{Ordering, AtomicBool};
use tokio::sync::mpsc;
const NUM: usize = 100;
let rt = rt();
let running = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:34 | tasks.push(task::spawn(async move {
while rx1.recv().await.is_some() {
tx2.send(()).unwrap();
}
}));
}
for _ in 0..NUM {
spawned_rx.recv().await.unwrap();
}
// spawn another ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:35 | rt.spawn(async move {
rx.await.unwrap();
});
}
// Prime the tasks
rt.block_on(async { tokio::task::yield_now().await });
let th = std::thread::spawn(move || {
tx.send(()).unwrap();
for tx in txs.drain(.... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:36 | by_ref: bool,
waker: Option<Waker>,
done: Sender<bool>,
}
impl Drop for TLData {
fn drop(&mut self) {
if self.by_ref {
self.waker.take().unwrap().wake_by_ref();
} else {
self.waker.take().unwrap(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7f09959b0a13cbea2b0e5c20ec1b7ac3f208dbad/tokio/tests/rt_common.rs | 1,401 | 1,444 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![allow(unknown_lints, unexpected_cfgs)]
#![allow(clippy::needless_range_loop)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(not(miri))]
// Tests to run on both current-thread & multi-thread runtime variants.
macro_rules! rt_test {
($($t:tt)*) => {
mod current_thread_scheduler {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | #[test]
fn spawn_one_bg() {
let rt = rt();
let out = rt.block_on(async {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
tx.send("ZOMG").unwrap();
});
assert_ok!(rx.await)
});
assert_eq!(out, "ZOMG");
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | #[test]
fn spawn_two() {
let rt = rt();
let out = rt.block_on(async {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
tokio::spawn(async move {
assert_ok!(tx1.send("ZOMG"));
});
tokio::spawn(asyn... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | tokio::spawn(async move {
let msg = assert_ok!(rx.await);
assert_eq!(i, msg);
assert_ok!(done_tx.send(msg));
});
tx
})
.collect::<Vec<_>>();
drop(done_tx);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | let rt = rt();
let out = rt.block_on(async {
tokio::spawn(async move {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (tx, rx) = oneshot::channel();
l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | assert_eq!(ITER, out.len());
for i in 0..ITER {
assert_eq!(i, out[i]);
}
}
#[test]
fn spawn_one_from_block_on_called_on_handle() {
let rt = rt();
let (tx, rx) = oneshot::channel();
#[allow(clippy::async_yields_async)]
let handle = rt.handle().bl... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | }).await)
}).await)
});
assert_eq!(out, "hello");
}
#[test]
fn outstanding_tasks_dropped() {
let rt = rt();
let cnt = Arc::new(());
rt.block_on(async {
let cnt = cnt.clone();
tokio::spawn(poll_fn(move |_| {
asse... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | let rt1 = rt();
let rt2 = rt1.block_on(async { rt() });
let out = rt2.block_on(async { "ZOMG" });
assert_eq!(out, "ZOMG");
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn complete_block_on_under_load() {
let rt = rt();
rt.block_on(as... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | // Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx1.send(()));
});
tokio::spaw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | }
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn spawn_from_other_thread_under_load() {
let rt = rt();
let handle = rt.clone();
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
handle.spawn(async move {
asser... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | }
#[test]
fn sleep_in_spawn() {
let rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
time::sleep(dur).await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn spawn_from_blocking() {
let rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | let rt = rt();
rt.block_on(async move {
assert_ok!(tokio::task::spawn_blocking(|| {
let now = std::time::Instant::now();
let dur = Duration::from_millis(1);
// use the futures' block_on fn to make sure we aren't setting
// any Tokio c... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | });
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn always_active_parker() {
// This test it to show that we will always have
// an active parker even if we call block_on concurrently
let rt = rt();
let rt2 = rt.clone();
let (tx1, rx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | // reason (mutex), they yield their ownership.
//
// This test hits an edge case on windows where more threads than cores are
// created, none of those threads ever yield due to being at capacity, so
// IOCP gets "starved".
//
// For now, this is a very edge case that is probably not a real prod... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | let mut stream = assert_ok!(TcpStream::connect(addr).await);
let mut dst = vec![0; 11];
assert_ok!(stream.read_exact(&mut dst).await);
assert_eq!(dst, b"hello world");
});
assert_ok!(srv.await);
assert_ok!(cli.await);
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | /// Implementation of `yield_defers_until_park` test. Returns `true` if the
/// test passed.
#[cfg(not(target_os="wasi"))]
fn yield_defers_until_park_inner() -> bool {
use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
use std::sync::Barrier;
let rt = rt();
let flag = A... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | let _socket = std::net::TcpStream::connect(addr).unwrap();
// Yield until connected
let mut cnt = 0;
while !flag_clone.load(SeqCst){
tokio::task::yield_now().await;
cnt += 1;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | success
})
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[cfg_attr(miri, ignore)] // No `socket` in miri.
#[test]
fn client_server_block_on() {
let rt = rt();
let (tx, rx) = mpsc::channel();
rt.block_on(async move { client_server(tx).await });
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | fn eagerly_drops_futures_on_shutdown() {
use std::sync::mpsc;
struct Never {
drop_tx: mpsc::Sender<()>,
}
impl Future for Never {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
Poll::Pending
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | #[test]
fn wake_while_rt_is_dropping() {
use tokio::sync::Barrier;
struct OnDrop<F: FnMut()>(F);
impl<F: FnMut()> Drop for OnDrop<F> {
fn drop(&mut self) {
(self.0)()
}
}
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/tests/rt_common.rs:26 | });
// Wait until every oneshot channel has been polled.
rt.block_on(barrier.wait());
// Drop the rt. Regardless of which task is dropped first, its destructor will wake the
// other task.
drop(rt);
}
#[cfg(not(target_os="wasi"))] // Wasi doesn't support UDP or bind()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,001 | 1,060 |
tokio-rs/tokio:tokio/tests/rt_common.rs:27 | });
tokio::time::sleep(Duration::from_millis(5)).await;
});
}
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn shutdown_timeout() {
let (tx, rx) = oneshot::channel();
let runtime = rt();
runtime.block_on(async move... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,041 | 1,100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:28 | #[test]
fn shutdown_wakeup_time() {
let runtime = rt();
runtime.block_on(async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
});
Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_secs(10_000));
}
// This test is current... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,081 | 1,140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:29 | // Get the assigned address
let addr = assert_ok!(server.local_addr());
// Spawn the server
tokio::spawn(async move {
// Accept a socket
let (mut socket, _) = server.accept().await.unwrap();
// Write some data
socket.write_all(b"hello").await.unw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,121 | 1,180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:30 | TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
}
#[cfg(not(target_os = "wasi"))] // Wasi does not support bind
#[cfg_attr(miri, ignore)] // No `socket` in miri.
#[test]
fn local_set_client_server_block_on() {
let rt = rt();
let (tx, rx) = mpsc::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,161 | 1,220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:31 | assert_eq!(buf, b"hello");
tx.send(()).unwrap();
}
#[test]
fn coop() {
use std::task::Poll::Ready;
use tokio::sync::mpsc;
let rt = rt();
rt.block_on(async {
let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,201 | 1,260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:32 | rt.block_on(async {
let (send, mut recv) = mpsc::unbounded_channel();
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}
tokio::task::unconstrained(poll_fn(|cx| {
// All the responses should be ready.
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,241 | 1,300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:33 | }).await;
});
}
// Tests that the "next task" scheduler optimization is not able to starve
// other tasks.
#[test]
fn ping_pong_saturation() {
use std::sync::atomic::{Ordering, AtomicBool};
use tokio::sync::mpsc;
const NUM: usize = 100;
let rt = rt();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,281 | 1,340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:34 | }));
tasks.push(task::spawn(async move {
while rx1.recv().await.is_some() {
tx2.send(()).unwrap();
}
}));
}
for _ in 0..NUM {
spawned_rx.recv().await.unwrap();
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,321 | 1,380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:35 | txs.push(tx);
rt.spawn(async move {
rx.await.unwrap();
});
}
// Prime the tasks
rt.block_on(async { tokio::task::yield_now().await });
let th = std::thread::spawn(move || {
tx.send(()).unwrap();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,361 | 1,420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:36 | struct TLData {
by_ref: bool,
waker: Option<Waker>,
done: Sender<bool>,
}
impl Drop for TLData {
fn drop(&mut self) {
if self.by_ref {
self.waker.take().unwrap().wake_by_ref();
} else {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4047d7962a02722859b0f1c7bbcd85bc1bfc865d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4047d7962a02722859b0f1c7bbcd85bc1bfc865d/tokio/tests/rt_common.rs | 1,401 | 1,445 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | }
#[test]
fn sleep_in_spawn() {
let rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
time::sleep(dur).await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | rx.await.unwrap();
});
}
#[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn spawn_from_blocking() {
let rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spawn_blocking(|| {
tokio::spawn(async mo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | rt.block_on(async move {
assert_ok!(tokio::task::spawn_blocking(|| {
let now = std::time::Instant::now();
let dur = Duration::from_millis(1);
// use the futures' block_on fn to make sure we aren't setting
// any Tokio context
f... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | #[cfg(not(target_os="wasi"))] // Wasi does not support threads
#[test]
fn always_active_parker() {
// This test it to show that we will always have
// an active parker even if we call block_on concurrently
let rt = rt();
let rt2 = rt.clone();
let (tx1, rx1) = oneshot::c... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | // This test hits an edge case on windows where more threads than cores are
// created, none of those threads ever yield due to being at capacity, so
// IOCP gets "starved".
//
// For now, this is a very edge case that is probably not a real production
// concern. There also isn't a great/obvious so... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | assert_ok!(stream.read_exact(&mut dst).await);
assert_eq!(dst, b"hello world");
});
assert_ok!(srv.await);
assert_ok!(cli.await);
});
}
/// Tests that yielded tasks are not scheduled until **after** resource
/// drivers are polled.
///
//... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
use std::sync::Barrier;
let rt = rt();
let flag = Arc::new(AtomicBool::new(false));
let barrier = Arc::new(Barrier::new(NUM_WORKERS));
rt.block_on(async {
// Make sure other workers cannot steal tasks
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 161b8c80d58a4a070c7f41db18d43ea258737db7 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/161b8c80d58a4a070c7f41db18d43ea258737db7/tokio/tests/rt_common.rs | 761 | 820 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.