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:24 | let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
task::spawn_local(async move {
let _ = listener.accept().await;
tx.send(()).unwrap();
});
TcpStream::connect(&addr).await.unwra... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 98e78314794607d0b402d5e45c66e3b8e38b819c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98e78314794607d0b402d5e45c66e3b8e38b819c/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | 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();
}
#[test]
fn coop() {
use std::task::Poll::Ready;
let mut rt = rt();
rt.... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 98e78314794607d0b402d5e45c66e3b8e38b819c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98e78314794607d0b402d5e45c66e3b8e38b819c/tokio/tests/rt_common.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/tests/rt_common.rs:26 | #[test]
fn ping_pong_saturation() {
use tokio::sync::mpsc;
const NUM: usize = 100;
let mut rt = rt();
rt.block_on(async {
let (spawned_tx, mut spawned_rx) = mpsc::unbounded_channel();
// Spawn a bunch of tasks that ping ping between each other to
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 98e78314794607d0b402d5e45c66e3b8e38b819c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98e78314794607d0b402d5e45c66e3b8e38b819c/tokio/tests/rt_common.rs | 1,001 | 1,052 |
tokio-rs/tokio:tokio/tests/rt_common.rs:27 | // 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 | 98e78314794607d0b402d5e45c66e3b8e38b819c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/98e78314794607d0b402d5e45c66e3b8e38b819c/tokio/tests/rt_common.rs | 1,041 | 1,052 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | }
#[test]
fn socket_from_blocking() {
let mut rt = rt();
rt.block_on(async move {
let mut listener = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
let addr = assert_ok!(listener.local_addr());
let peer = tokio::task::spawn_blocking(move || {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | }
#[test]
fn io_driver_called_when_under_load() {
let mut rt = rt();
// Create a lot of constant load. The scheduler will always be busy.
for _ in 0..100 {
rt.spawn(async {
loop {
tokio::task::yield_now().await;
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | let mut rt = rt();
let (tx, rx) = mpsc::channel();
rt.block_on(async move { client_server(tx).await });
assert_ok!(rx.try_recv());
assert_err!(rx.try_recv());
}
#[test]
fn panic_in_task() {
let mut rt = rt();
let (tx, rx) = oneshot::channel();
stru... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | }
async fn yield_once() {
let mut yielded = false;
poll_fn(|cx| {
if yielded {
Poll::Ready(())
} else {
yielded = true;
cx.waker().wake_by_ref();
Poll::Pending
}
})
.await
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | }
impl Drop for Never {
fn drop(&mut self) {
self.drop_tx.send(()).unwrap();
}
}
let mut rt = rt();
let (drop_tx, drop_rx) = mpsc::channel();
let (run_tx, run_rx) = oneshot::channel();
rt.block_on(async move {
tokio:... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
let (tx3, rx3) = oneshot::channel();
let mut rt = rt();
let h1 = rt.handle().clone();
rt.handle().spawn(async move {
// Ensure a waker gets stored in oneshot 1.
let _ = rx1.await;... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | task::yield_now().await;
});
// Drop the rt
drop(rt);
}
#[test]
fn io_notify_while_shutting_down() {
use std::net::Ipv6Addr;
for _ in 1..10 {
let mut runtime = rt();
runtime.block_on(async {
let socket = UdpSocket::bind((Ipv... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | #[test]
fn shutdown_timeout() {
let (tx, rx) = oneshot::channel();
let mut runtime = rt();
runtime.block_on(async move {
task::spawn_blocking(move || {
tx.send(()).unwrap();
thread::sleep(Duration::from_secs(10_000));
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:23 | // 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.unwrap();
});
let mut client = TcpStream::connect(&addr).await.unwrap();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 881 | 940 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | #[test]
fn local_set_client_server_block_on() {
let mut rt = rt();
let (tx, rx) = mpsc::channel();
let local = task::LocalSet::new();
local.block_on(&mut rt, async move { client_server_local(tx).await });
assert_ok!(rx.try_recv());
assert_err!(rx.try_recv());
}... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | let mut rt = rt();
rt.block_on(async {
// Create a bunch of tasks
let mut tasks = (0..1_000).map(|_| {
tokio::spawn(async { })
}).collect::<Vec<_>>();
// Hope that all the tasks complete...
time::delay_for(Duration::from_millis(100)).... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 961 | 1,020 |
tokio-rs/tokio:tokio/tests/rt_common.rs:26 | for _ in 0..NUM {
let (tx1, mut rx1) = mpsc::unbounded_channel();
let (tx2, mut rx2) = mpsc::unbounded_channel();
let spawned_tx = spawned_tx.clone();
task::spawn(async move {
spawned_tx.send(()).unwrap();
tx1.send... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d8139fef7a555f99adaa37e139787d26e24daba3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d8139fef7a555f99adaa37e139787d26e24daba3/tokio/tests/rt_common.rs | 1,001 | 1,039 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | .enable_all()
.build()
.unwrap()
}
}
}
}
#[test]
fn send_sync_bound() {
use tokio::runtime::Runtime;
fn is_send<T: Send + Sync>() {}
is_send::<Runtime>();
}
rt_test! {
use tokio::net::{TcpListener, TcpStream, UdpSocket};
use tokio::p... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | assert!(win);
}
#[test]
fn block_on_async() {
let mut rt = rt();
let out = rt.block_on(async {
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
tx.send("ZOMG").unwrap();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | fn spawn_one_join() {
let mut rt = rt();
let out = rt.block_on(async {
let (tx, rx) = oneshot::channel();
let handle = tokio::spawn(async move {
tx.send("ZOMG").unwrap();
"DONE"
});
let msg = assert_ok!(rx.await);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | });
assert_eq!(out, "ZOMG");
}
#[test]
fn spawn_many_from_block_on() {
use tokio::sync::mpsc;
const ITER: usize = 200;
let mut rt = rt();
let out = rt.block_on(async {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | while let Some(i) = done_rx.recv().await {
out.push(i);
}
out.sort();
out
});
assert_eq!(ITER, out.len());
for i in 0..ITER {
assert_eq!(i, out[i]);
}
}
#[test]
fn spawn_many_from_task() {
use tokio::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/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<_>>();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | assert_ok!(tokio::spawn(async {
assert_ok!(tokio::spawn(async {
"hello"
}).await)
}).await)
});
assert_eq!(out, "hello");
}
#[test]
fn outstanding_tasks_dropped() {
let mut rt = rt();
let cnt = Arc::new(());
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | #[test]
fn create_rt_in_block_on() {
let mut rt1 = rt();
let mut rt2 = rt1.block_on(async { rt() });
let out = rt2.block_on(async { "ZOMG" });
assert_eq!(out, "ZOMG");
}
#[test]
fn complete_block_on_under_load() {
let mut rt = rt();
rt.block_on(async {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | // 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 | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | }
#[test]
fn spawn_from_other_thread_under_load() {
let mut rt = rt();
let handle = rt.handle().clone();
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
handle.spawn(async move {
assert_ok!(tx.send(()));
});
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | #[test]
fn delay_in_spawn() {
let mut 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::delay_for(dur).await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | }
#[test]
fn spawn_from_blocking() {
let mut rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spawn_blocking(|| {
tokio::spawn(async move { "hello" })
}).await);
assert_ok!(inner.await)
});
a... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | // use the futures' block_on fn to make sure we aren't setting
// any Tokio context
futures::executor::block_on(async {
tokio::time::delay_for(dur).await;
});
assert!(now.elapsed() >= dur);
}).await);
});
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | // Shutdown
drop(rt);
handle.enter(|| {
let res = task::spawn_blocking(|| unreachable!());
// Avoid using a tokio runtime
let out = futures::executor::block_on(res);
assert!(out.is_err());
});
}
#[test]
fn io_driver_called_when_under... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | assert_eq!(dst, b"hello world");
});
assert_ok!(srv.await);
assert_ok!(cli.await);
});
}
#[test]
fn client_server_block_on() {
let mut 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 | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | rt.spawn(Boom(Some(tx)));
assert_ok!(rt.block_on(rx));
}
#[test]
#[should_panic]
fn panic_in_block_on() {
let mut rt = rt();
rt.block_on(async { panic!() });
}
async fn yield_once() {
let mut yielded = false;
poll_fn(|cx| {
if yielded {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | 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 {
fn drop(&mut sel... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | use tokio::task;
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) = oneshot::channel();
let (tx3, rx3) = oneshot::channel(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | rt.handle().spawn(async move {
let _ = rx3.await;
// We'll never get here, but once task 3 drops, this will
// force task 2 to re-schedule since it's waiting on oneshot 2.
tx2.send(()).unwrap();
});
// Tick the loop
rt.block_on(async {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | send_half.send_to(&buf, &addr).await.unwrap();
tokio::time::delay_for(Duration::from_millis(1)).await;
}
});
tokio::time::delay_for(Duration::from_millis(5)).await;
});
}
}
#[test]
fn shutdown_timeout() {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | let _rt = rt();
}).join().unwrap();
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
// Get the assigned address
let addr = assert_ok!(server.local_addr());
// Spawn the server
tokio::spawn(as... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:23 | task::spawn_local(async move {
let _ = listener.accept().await;
tx.send(()).unwrap();
});
TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
}
#[test]
fn local_set_client_server_block_on() {
let mut rt = rt()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 881 | 940 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | let mut buf = vec![];
client.read_to_end(&mut buf).await.unwrap();
assert_eq!(buf, b"hello");
tx.send(()).unwrap();
}
#[test]
fn coop() {
use std::task::Poll::Ready;
let mut rt = rt();
rt.block_on(async {
// Create a bunch of tasks
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 921 | 980 |
tokio-rs/tokio:tokio/tests/rt_common.rs:25 | const NUM: usize = 100;
let mut rt = rt();
rt.block_on(async {
let (spawned_tx, mut spawned_rx) = mpsc::unbounded_channel();
// Spawn a bunch of tasks that ping ping between each other to
// saturate the runtime.
for _ in 0..NUM {
let (t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | fa4fe9ef6feea7c8c88c81559797e57da7368b36 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fa4fe9ef6feea7c8c88c81559797e57da7368b36/tokio/tests/rt_common.rs | 961 | 1,009 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![allow(clippy::needless_range_loop)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
// Tests to run on both current-thread & therad-pool runtime variants.
macro_rules! rt_test {
($($t:tt)*) => {
mod basic_scheduler {
$($t)*
fn rt() -> Runtime {
tokio::runti... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | }
rt_test! {
use tokio::net::{TcpListener, TcpStream, UdpSocket};
use tokio::prelude::*;
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio::{task, time};
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
use std::future::Future;
use std::pin::Pin... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | });
assert_ok!(rx.await)
});
assert_eq!(out, "ZOMG");
}
#[test]
fn spawn_one_bg() {
let mut rt = rt();
let out = rt.block_on(async {
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
tx.send("ZOMG").unwrap();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | assert_eq!(out, "DONE");
msg
});
assert_eq!(out, "ZOMG");
}
#[test]
fn spawn_two() {
let mut rt = rt();
let out = rt.block_on(async {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
tokio::spawn(as... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (tx, rx) = oneshot::channel();
let done_tx = done_tx.clone();
tokio::spawn(async move {
let msg = assert_ok!(rx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | #[test]
fn spawn_await_chain() {
let mut rt = rt();
let out = rt.block_on(async {
assert_ok!(tokio::spawn(async {
assert_ok!(tokio::spawn(async {
"hello"
}).await)
}).await)
});
assert_eq!(out, "hello");
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | fn nested_rt() {
let mut rt1 = rt();
let mut rt2 = rt();
rt1.block_on(async { rt2.block_on(async { "hello" }) });
}
#[test]
fn create_rt_in_block_on() {
let mut rt1 = rt();
let mut rt2 = rt1.block_on(async { rt() });
let out = rt2.block_on(async { "ZOMG" });... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | fn complete_task_under_load() {
let mut rt = rt();
rt.block_on(async {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | });
});
rt.block_on(async move {
assert_ok!(rx.await);
});
}
#[test]
fn spawn_from_other_thread_under_load() {
let mut rt = rt();
let handle = rt.handle().clone();
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
h... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | rt.block_on(async move {
time::delay_for(dur).await;
});
assert!(now.elapsed() >= dur);
}
#[test]
fn delay_in_spawn() {
let mut rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
let (... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | tx.send(()).unwrap();
});
TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
}
#[test]
fn spawn_from_blocking() {
let mut rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spawn_blocking(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | let mut 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 Tok... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | #[test]
fn spawn_blocking_after_shutdown() {
let rt = rt();
let handle = rt.handle().clone();
// Shutdown
drop(rt);
handle.enter(|| {
let res = task::spawn_blocking(|| unreachable!());
// Avoid using a tokio runtime
let out = futures::ex... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | let cli = tokio::spawn(async move {
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);... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | impl Drop for Boom {
fn drop(&mut self) {
assert!(std::thread::panicking());
self.0.take().unwrap().send(()).unwrap();
}
}
rt.spawn(Boom(Some(tx)));
assert_ok!(rt.block_on(rx));
}
#[test]
#[should_panic]
fn panic_in_block_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | }
#[test]
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<()> {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | assert_ok!(drop_rx.recv());
}
#[test]
fn wake_while_rt_is_dropping() {
use tokio::task;
struct OnDrop<F: FnMut()>(F);
impl<F: FnMut()> Drop for OnDrop<F> {
fn drop(&mut self) {
(self.0)()
}
}
let (tx1, rx1) = oneshot::channe... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | h1.spawn(async move {
tx1.send(()).unwrap();
});
});
let _ = rx2.await;
});
rt.handle().spawn(async move {
let _ = rx3.await;
// We'll never get here, but once task 3 drops, this will
// force task 2 to re-s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | }
});
tokio::spawn(async move {
let buf = [0];
loop {
send_half.send_to(&buf, &addr).await.unwrap();
tokio::time::delay_for(Duration::from_millis(1)).await;
}
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | );
thread::spawn(|| {
R.with(|cell| {
*cell.borrow_mut() = Some(rt());
});
let _rt = rt();
}).join().unwrap();
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | local.block_on(&mut rt, async move {
let (tx, rx) = oneshot::channel();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
task::spawn_local(async move {
let _ = listener.accept().await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 801 | 860 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | // Write some data
socket.write_all(b"hello").await.unwrap();
});
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();
}
#[tes... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 841 | 900 |
tokio-rs/tokio:tokio/tests/rt_common.rs:23 | // Tests that the "next task" scheduler optimization is not able to starve
// other tasks.
#[test]
fn ping_pong_saturation() {
use tokio::sync::mpsc;
const NUM: usize = 100;
let mut rt = rt();
rt.block_on(async {
let (spawned_tx, mut spawned_rx) = mpsc::unbound... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 881 | 935 |
tokio-rs/tokio:tokio/tests/rt_common.rs:24 | 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.
task::yie... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | caa7e180e43fdf914774de86f01f88e6b41f4a32 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/caa7e180e43fdf914774de86f01f88e6b41f4a32/tokio/tests/rt_common.rs | 921 | 935 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | // Write some data
socket.write_all(b"hello").await.unwrap();
});
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();
}
#[tes... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 11acfbbea4668b5dfe47357e9f52a7cd1f816416 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/11acfbbea4668b5dfe47357e9f52a7cd1f816416/tokio/tests/rt_common.rs | 841 | 881 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | local.block_on(&mut rt, async move {
let (tx, rx) = oneshot::channel();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
task::spawn_local(async move {
let _ = listener.accept().await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/tests/rt_common.rs | 801 | 853 |
tokio-rs/tokio:tokio/tests/rt_common.rs:22 | // Write some data
socket.write_all(b"hello").await.unwrap();
});
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();
}
} | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a78b1c65ccfb9692ca5d3ed8ddde934f40091d83 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a78b1c65ccfb9692ca5d3ed8ddde934f40091d83/tokio/tests/rt_common.rs | 841 | 853 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | fn complete_task_under_load() {
let mut rt = rt();
rt.block_on(async {
let (tx1, rx1) = oneshot::channel();
let (tx2, rx2) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | });
});
rt.block_on(async move {
assert_ok!(rx.await);
});
}
#[test]
fn delay_at_root() {
let mut rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
time::delay_for(dur).await;... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | assert!(now.elapsed() >= dur);
}
#[test]
fn block_on_socket() {
let mut rt = rt();
rt.block_on(async move {
let (tx, rx) = oneshot::channel();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | let mut rt = rt();
let out = rt.block_on(async move {
let inner = assert_ok!(tokio::task::spawn_blocking(|| {
tokio::task::spawn_blocking(|| "hello")
}).await);
assert_ok!(inner.await)
});
assert_eq!(out, "hello")
}
#[test]
fn d... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | let peer = tokio::task::spawn_blocking(move || {
// use the futures' block_on fn to make sure we aren't setting
// any Tokio context
futures::executor::block_on(async {
assert_ok!(TcpStream::connect(addr).await);
});
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | loop {
tokio::task::yield_now().await;
}
});
}
// Do some I/O work
rt.block_on(async {
let mut listener = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
let addr = assert_ok!(listener.local_addr());
let sr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | #[test]
fn panic_in_task() {
let mut rt = rt();
let (tx, rx) = oneshot::channel();
struct Boom(Option<oneshot::Sender<()>>);
impl Future for Boom {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
panic!()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | cx.waker().wake_by_ref();
Poll::Pending
}
})
.await
}
#[test]
fn enter_and_spawn() {
let mut rt = rt();
let handle = rt.enter(|| {
tokio::spawn(async {})
});
assert_ok!(rt.block_on(handle));
}
#[test]
fn e... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | let (drop_tx, drop_rx) = mpsc::channel();
let (run_tx, run_rx) = oneshot::channel();
rt.block_on(async move {
tokio::spawn(async move {
assert_ok!(run_tx.send(()));
Never { drop_tx }.await
});
assert_ok!(run_rx.await);
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | // Ensure a waker gets stored in oneshot 1.
let _ = rx1.await;
tx3.send(()).unwrap();
});
rt.handle().spawn(async move {
// When this task is dropped, we'll be "closing remotes".
// We spawn a new task that owns the `tx1`, to move its Drop
// ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | use std::net::Ipv6Addr;
for _ in 1..100 {
let mut runtime = rt();
runtime.block_on(async {
let socket = UdpSocket::bind((Ipv6Addr::LOCALHOST, 0)).await.unwrap();
let addr = socket.local_addr().unwrap();
let (mut recv_half, mut send_half) ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | });
rx.await.unwrap();
});
runtime.shutdown_timeout(Duration::from_millis(100));
}
#[test]
fn runtime_in_thread_local() {
use std::cell::RefCell;
use std::thread;
thread_local!(
static R: RefCell<Option<Runtime>> = RefCell::new(None);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | 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();
}
mod local_set {
use tokio::task;
use super::*;
#[test]
fn block_on_... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 761 | 820 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | let local = task::LocalSet::new();
local.block_on(&mut rt, async move { client_server_local(tx).await });
assert_ok!(rx.try_recv());
assert_err!(rx.try_recv());
}
async fn client_server_local(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListen... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 9d6b99494b72e79b4afba5073a9ebef5bbbeca8a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/9d6b99494b72e79b4afba5073a9ebef5bbbeca8a/tokio/tests/rt_common.rs | 801 | 833 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | use std::net::Ipv6Addr;
for _ in 1..100 {
let mut runtime = rt();
runtime.block_on(async {
let socket = UdpSocket::bind((Ipv6Addr::LOCALHOST, 0)).await.unwrap();
let addr = socket.local_addr().unwrap();
let (mut recv_half, mut send_half) ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/tests/rt_common.rs | 681 | 740 |
tokio-rs/tokio:tokio/tests/rt_common.rs:19 | thread::spawn(|| {
R.with(|cell| {
*cell.borrow_mut() = Some(rt());
});
let _rt = rt();
}).join().unwrap();
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
// Get ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/tests/rt_common.rs | 721 | 780 |
tokio-rs/tokio:tokio/tests/rt_common.rs:20 | let local = task::LocalSet::new();
local.block_on(&mut rt, async move {
let (tx, rx) = oneshot::channel();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
task::spawn_local(async... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/tests/rt_common.rs | 761 | 816 |
tokio-rs/tokio:tokio/tests/rt_common.rs:21 | let (mut socket, _) = server.accept().await.unwrap();
// Write some data
socket.write_all(b"hello").await.unwrap();
});
let mut client = TcpStream::connect(&addr).await.unwrap();
let mut buf = vec![];
client.read_to_end(&mut buf).await.u... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 6406328176cdecf15cad69b327597a4d4d0b8e20 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6406328176cdecf15cad69b327597a4d4d0b8e20/tokio/tests/rt_common.rs | 801 | 816 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![allow(clippy::needless_range_loop)]
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
// Tests to run on both current-thread & therad-pool runtime variants.
macro_rules! rt_test {
($($t:tt)*) => {
mod basic_scheduler {
$($t)*
fn rt() -> Runtime {
tokio::runti... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | dcfa895b512e3ed522b81b18baf3e33fd78a600c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dcfa895b512e3ed522b81b18baf3e33fd78a600c/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | }
rt_test! {
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio::{task, time};
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | dcfa895b512e3ed522b81b18baf3e33fd78a600c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dcfa895b512e3ed522b81b18baf3e33fd78a600c/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | let (drop_tx, drop_rx) = mpsc::channel();
let (run_tx, run_rx) = oneshot::channel();
rt.block_on(async move {
tokio::spawn(async move {
assert_ok!(run_tx.send(()));
Never { drop_tx }.await
});
assert_ok!(run_rx.await);
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | dcfa895b512e3ed522b81b18baf3e33fd78a600c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dcfa895b512e3ed522b81b18baf3e33fd78a600c/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | // 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 | dcfa895b512e3ed522b81b18baf3e33fd78a600c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dcfa895b512e3ed522b81b18baf3e33fd78a600c/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
}
#[test]
fn client_server_block_on() {
let mut rt = rt();
let (tx, rx) = mpsc::channel();
let local = task::LocalSet::new();
local.block_on(&mut rt, as... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | dcfa895b512e3ed522b81b18baf3e33fd78a600c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/dcfa895b512e3ed522b81b18baf3e33fd78a600c/tokio/tests/rt_common.rs | 681 | 724 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | loop {
tokio::task::yield_now().await;
}
});
}
// Do some I/O work
rt.block_on(async {
let mut listener = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
let addr = assert_ok!(listener.local_addr());
let sr... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | adc5186ebd1290c2f144e153a87e147d257f8b0f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/adc5186ebd1290c2f144e153a87e147d257f8b0f/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | #[test]
fn panic_in_task() {
let mut rt = rt();
let (tx, rx) = oneshot::channel();
struct Boom(Option<oneshot::Sender<()>>);
impl Future for Boom {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
panic!()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | adc5186ebd1290c2f144e153a87e147d257f8b0f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/adc5186ebd1290c2f144e153a87e147d257f8b0f/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | cx.waker().wake_by_ref();
Poll::Pending
}
})
.await
}
#[test]
fn enter_and_spawn() {
let mut rt = rt();
let handle = rt.enter(|| {
tokio::spawn(async {})
});
assert_ok!(rt.block_on(handle));
}
#[test]
fn e... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3d1b4b30585532e9708e322e1a0876d2933af71a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3d1b4b30585532e9708e322e1a0876d2933af71a/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | let (drop_tx, drop_rx) = mpsc::channel();
let (run_tx, run_rx) = oneshot::channel();
rt.block_on(async move {
tokio::spawn(async move {
assert_ok!(run_tx.send(()));
Never { drop_tx }.await
});
assert_ok!(run_rx.await);
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3d1b4b30585532e9708e322e1a0876d2933af71a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3d1b4b30585532e9708e322e1a0876d2933af71a/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | tx.send(()).unwrap();
}
mod local_set {
use tokio::task;
use super::*;
#[test]
fn block_on_socket() {
let mut rt = rt();
let local = task::LocalSet::new();
local.block_on(&mut rt, async move {
let (tx, rx) = oneshot::channel(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3d1b4b30585532e9708e322e1a0876d2933af71a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3d1b4b30585532e9708e322e1a0876d2933af71a/tokio/tests/rt_common.rs | 641 | 700 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | async fn client_server_local(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
// Get the assigned address
let addr = assert_ok!(server.local_addr());
// Spawn the server
task::spawn_local(async move {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3d1b4b30585532e9708e322e1a0876d2933af71a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3d1b4b30585532e9708e322e1a0876d2933af71a/tokio/tests/rt_common.rs | 681 | 706 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | assert!(now.elapsed() >= dur);
}
#[test]
fn block_on_socket() {
let mut rt = rt();
rt.block_on(async move {
let (tx, rx) = oneshot::channel();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | let cli = tokio::spawn(async move {
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);... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | impl Drop for Boom {
fn drop(&mut self) {
assert!(::std::thread::panicking());
self.0.take().unwrap().send(()).unwrap();
}
}
rt.spawn(Boom(Some(tx)));
assert_ok!(rt.block_on(rx));
}
#[test]
#[should_panic]
fn panic_in_bloc... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | }
#[test]
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<()> {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/tests/rt_common.rs | 561 | 620 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.