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:16 | assert_ok!(drop_rx.recv());
}
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(async move {
... | 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 | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | 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::co... | 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 | 641 | 691 |
tokio-rs/tokio:tokio/tests/rt_common.rs:18 | 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 | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/tests/rt_common.rs | 681 | 691 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![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::runtime::Builder::new()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/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 std:... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/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 | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | 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(async move {
assert_ok!(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | 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.await);
assert_eq!(i, msg);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/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 | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | 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" });
assert_eq!(out,... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | 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;
}
});
threa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/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 | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | }
#[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();
tokio::spawn(async mo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | 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 | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 401 | 460 |
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 | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | 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_on() {
let mut rt = rt(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/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<()> {
Poll::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | assert_ok!(drop_rx.recv());
}
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(async move {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 601 | 660 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | let addr = listener.local_addr().unwrap();
task::spawn_local(async move {
let _ = listener.accept().await;
tx.send(()).unwrap();
});
TcpStream::connect(&addr).await.unwrap();
rx.await.unwrap();
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a8a4a9f0fceb33162bfb34160ac8ceb098c65ee3/tokio/tests/rt_common.rs | 641 | 690 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | #![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::runtime::Builder::new()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/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::time;
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use std::sync::{... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | 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 | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | #[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 | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | 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();
struct Boom(Option<oneshot::Sender<()>>);
impl Future for Boom ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | 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
}
#[test]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | 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::spawn(asyn... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a2cfc877a7f45eb0e1ae8d2775e22ee91da725ec/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | 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.await);
assert_eq!(i, msg);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | #[test]
fn complete_block_on_under_load() {
let mut rt = rt();
rt.block_on(async {
let (tx, rx) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | assert_ok!(tx1.send(()));
});
tokio::spawn(async move {
assert_ok!(rx1.await);
assert_ok!(tx2.send(()));
});
assert_ok!(rx2.await);
});
}
#[test]
fn spawn_from_other_thread() {
let mut rt = rt();
let h... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | 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 (tx, rx) = oneshot::channel();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | });
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(|| {
tokio::spawn(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | }
#[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 | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | let mut listener = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
let addr = assert_ok!(listener.local_addr());
let srv = tokio::spawn(async move {
let (mut stream, _) = assert_ok!(listener.accept().await);
assert_ok!(stream.write_all(b"hello world").await);... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
panic!();
}
}
impl Drop for Boom {
fn drop(&mut self) {
assert!(::std::thread::panicking());
self.0.take().unwrap().send(()).unwrap()... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | fn enter_and_spawn() {
let mut rt = rt();
let handle = rt.enter(|| {
tokio::spawn(async {})
});
assert_ok!(rt.block_on(handle));
}
#[test]
fn eagerly_drops_futures_on_shutdown() {
use std::sync::mpsc;
struct Never {
drop_tx: mpsc::Se... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | Never { drop_tx }.await
});
assert_ok!(run_rx.await);
});
drop(rt);
assert_ok!(drop_rx.recv());
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
// Get the assigned address
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 561 | 620 |
tokio-rs/tokio:tokio/tests/rt_common.rs:16 | 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();
let mut listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listen... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 601 | 658 |
tokio-rs/tokio:tokio/tests/rt_common.rs:17 | task::spawn_local(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 | 38e602f4d812c196d5dc0bc245e79ccad4e77cfd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/38e602f4d812c196d5dc0bc245e79ccad4e77cfd/tokio/tests/rt_common.rs | 641 | 658 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | Never { drop_tx }.await
});
assert_ok!(run_rx.await);
});
drop(rt);
assert_ok!(drop_rx.recv());
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);
// Get the assigned address
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7b4c999341809588a427a9a80d310ee4aa1c1a21 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7b4c999341809588a427a9a80d310ee4aa1c1a21/tokio/tests/rt_common.rs | 561 | 595 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | // Tests to run on both current-thread & therad-pool runtime variants.
#![warn(rust_2018_idioms)]
macro_rules! rt_test {
($($t:tt)*) => {
mod basic_scheduler {
$($t)*
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.basic_scheduler()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 1 | 60 |
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 | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | 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(async move {
assert_ok!(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | 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.await);
assert_eq!(i, msg);
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | fn outstanding_tasks_dropped() {
let mut rt = rt();
let cnt = Arc::new(());
rt.block_on(async {
let cnt = cnt.clone();
tokio::spawn(poll_fn(move |_| {
assert_eq!(2, Arc::strong_count(&cnt));
Poll::<()>::Pending
}));
}... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | fn complete_block_on_under_load() {
let mut rt = rt();
rt.block_on(async {
let (tx, rx) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spaw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | });
tokio::spawn(async move {
assert_ok!(rx1.await);
assert_ok!(tx2.send(()));
});
assert_ok!(rx2.await);
});
}
#[test]
fn spawn_from_other_thread() {
let mut rt = rt();
let handle = rt.handle().clone();
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | });
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 (tx, rx) = oneshot::channel();
tokio::spawn(async move {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | 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(|| {
tokio::spawn(async move { "hel... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | #[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 | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 401 | 460 |
tokio-rs/tokio:tokio/tests/rt_common.rs:12 | let addr = assert_ok!(listener.local_addr());
let srv = tokio::spawn(async move {
let (mut stream, _) = assert_ok!(listener.accept().await);
assert_ok!(stream.write_all(b"hello world").await);
});
let cli = tokio::spawn(async move {
l... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 441 | 500 |
tokio-rs/tokio:tokio/tests/rt_common.rs:13 | fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
panic!();
}
}
impl Drop for Boom {
fn drop(&mut self) {
assert!(::std::thread::panicking());
self.0.take().unwrap().send(()).unwrap();
}
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 481 | 540 |
tokio-rs/tokio:tokio/tests/rt_common.rs:14 | let mut rt = rt();
let handle = rt.enter(|| {
tokio::spawn(async {})
});
assert_ok!(rt.block_on(handle));
}
#[test]
fn eagerly_drops_futures_on_shutdown() {
use std::sync::mpsc;
struct Never {
drop_tx: mpsc::Sender<()>,
}
im... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 521 | 580 |
tokio-rs/tokio:tokio/tests/rt_common.rs:15 | });
assert_ok!(run_rx.await);
});
drop(rt);
assert_ok!(drop_rx.recv());
}
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.... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8546ff826db8dba1e39b4119ad909fb6cab2492a | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8546ff826db8dba1e39b4119ad909fb6cab2492a/tokio/tests/rt_common.rs | 561 | 594 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | // Tests to run on both current-thread & therad-pool runtime variants.
#![warn(rust_2018_idioms)]
macro_rules! rt_test {
($($t:tt)*) => {
mod basic_scheduler {
$($t)*
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.basic_scheduler()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | use tokio::time;
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use std::sync::{mpsc, Arc};
use std::task::{Context, Poll};
use std::thread;
use std::time::{Duration, Instant};
#[test]
fn block_on_sync() {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | #[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();
});
assert_ok!(rx.await)
});
assert_eq!(out, "ZOMG")... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | #[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(async move {
assert_ok!(tx1.send("ZOMG"));
});
tokio::spawn(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | 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 | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | rt.block_on(async {
let cnt = cnt.clone();
tokio::spawn(poll_fn(move |_| {
assert_eq!(2, Arc::strong_count(&cnt));
Poll::<()>::Pending
}));
});
assert_eq!(2, Arc::strong_count(&cnt));
drop(rt);
assert_eq!(1, Arc::str... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | // Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx.send(()));
});
assert_ok!(r... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | });
assert_ok!(rx2.await);
});
}
#[test]
fn spawn_from_other_thread() {
let mut rt = rt();
let handle = rt.handle().clone();
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
h... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | #[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 | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | #[test]
fn client_server_block_on() {
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]
#[ignore]
fn panic_in_task() {
let rt = rt... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | #[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 {
Poll::Ready(())
} else {
yielded = true;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 4d19a999371190e25f6138916d93e6c75093e4a6 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4d19a999371190e25f6138916d93e6c75093e4a6/tokio/tests/rt_common.rs | 401 | 454 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | #[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 {
Poll::Ready(())
} else {
yielded = true;
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 19f1fc36bd567377bde4a2c6818c6b606d89d488 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/19f1fc36bd567377bde4a2c6818c6b606d89d488/tokio/tests/rt_common.rs | 401 | 444 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | use tokio::time;
use tokio_test::{assert_err, assert_ok};
use futures::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use std::sync::{mpsc, Arc};
use std::task::{Context, Poll};
use std::thread;
use std::time::{Duration, Instant};
#[test]
fn block_on_sync() {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | #[test]
fn spawn_one() {
let mut 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 | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | #[test]
fn spawn_many() {
use tokio::sync::mpsc;
const ITER: usize = 20;
let mut rt = rt();
let out = rt.block_on(async {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (tx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:5 | out.sort();
out
});
assert_eq!(ITER, out.len());
for i in 0..ITER {
assert_eq!(i, out[i]);
}
}
#[test]
fn outstanding_tasks_dropped() {
let mut rt = rt();
let cnt = Arc::new(());
rt.block_on(async {
let cnt = cn... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 161 | 220 |
tokio-rs/tokio:tokio/tests/rt_common.rs:6 | }
#[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(a... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | let (tx2, rx2) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx1.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | });
}
#[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;
});
assert!(now.elapsed() >= dur);
}
#[test]
fn delay_in_spaw... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common.rs:9 | let mut rt = Runtime::new().unwrap();
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();
tokio::spawn(async move {
let _ = li... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 321 | 380 |
tokio-rs/tokio:tokio/tests/rt_common.rs:10 | fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> {
panic!();
}
}
impl Drop for Boom {
fn drop(&mut self) {
assert!(::std::thread::panicking());
self.0.send(()).unwrap();
}
}
rt.spawn(Boo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 361 | 420 |
tokio-rs/tokio:tokio/tests/rt_common.rs:11 | // 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 | 3f0eabe7798de624f5ee9c7562803bfb97e6088f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3f0eabe7798de624f5ee9c7562803bfb97e6088f/tokio/tests/rt_common.rs | 401 | 421 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | // Tests to run on both current-thread & therad-pool runtime variants.
#![warn(rust_2018_idioms)]
macro_rules! rt_test {
($($t:tt)*) => {
mod current_thread {
$($t)*
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.current_thread()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | // Tests to run on both current-thread & therad-pool runtime variants.
#![warn(rust_2018_idioms)]
macro_rules! rt_test {
($($t:tt)*) => {
mod current_thread {
$($t)*
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.current_thread()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | use tokio::time;
use tokio_test::{assert_err, assert_ok};
use futures_util::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use std::sync::{mpsc, Arc};
use std::task::{Context, Poll};
use std::thread;
use std::time::{Duration, Instant};
#[test]
fn block_on_sync() {... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:3 | #[test]
fn spawn_one() {
let mut 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 | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/rt_common.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_common.rs:4 | #[test]
fn spawn_many() {
use tokio::sync::mpsc;
const ITER: usize = 20;
let mut rt = rt();
let out = rt.block_on(async {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (tx... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/tests/rt_common.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | let (tx2, rx2) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx1.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | 7e35922a1d282b1e3dadf037cd237be336b331fb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7e35922a1d282b1e3dadf037cd237be336b331fb/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:1 | // Tests to run on both current-thread & therad-pool runtime variants.
#![warn(rust_2018_idioms)]
macro_rules! rt_test {
($($t:tt)*) => {
mod current_thread {
$($t)*
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.current_thread()
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | e19bd77ef0149b3141981b36f3ebc442fae4a0b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e19bd77ef0149b3141981b36f3ebc442fae4a0b4/tokio/tests/rt_common.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common.rs:2 | use tokio::timer;
use tokio_test::{assert_err, assert_ok};
use futures_util::future::poll_fn;
use std::future::Future;
use std::pin::Pin;
use std::sync::{mpsc, Arc};
use std::task::{Context, Poll};
use std::thread;
use std::time::{Duration, Instant};
#[test]
fn block_on_sync() ... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | e19bd77ef0149b3141981b36f3ebc442fae4a0b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e19bd77ef0149b3141981b36f3ebc442fae4a0b4/tokio/tests/rt_common.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_common.rs:7 | let (tx2, rx2) = oneshot::channel();
// Spin hard
tokio::spawn(async {
loop {
yield_once().await;
}
});
thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
assert_ok!(tx1.s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | e19bd77ef0149b3141981b36f3ebc442fae4a0b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e19bd77ef0149b3141981b36f3ebc442fae4a0b4/tokio/tests/rt_common.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_common.rs:8 | });
}
#[test]
fn delay_at_root() {
let mut rt = rt();
let now = Instant::now();
let dur = Duration::from_millis(50);
rt.block_on(async move {
timer::delay_for(dur).await;
});
assert!(now.elapsed() >= dur);
}
#[test]
fn delay_in_spa... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common.rs | MIT | e19bd77ef0149b3141981b36f3ebc442fae4a0b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e19bd77ef0149b3141981b36f3ebc442fae4a0b4/tokio/tests/rt_common.rs | 281 | 340 |
tokio-rs/tokio:tokio/tests/rt_common_before_park.rs:1 | #![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use tokio::runtime::Builder;
use tokio::sync::Notify;
#[test]
fn before_park_wakes_block_on_task() {
let notify = Arc::new(Notify... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common_before_park.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common_before_park.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_common_before_park.rs:2 | fn before_park_spawns_task() {
let notify = Arc::new(Notify::new());
let notify2 = notify.clone();
let woken = Arc::new(AtomicBool::new(false));
let woken2 = woken.clone();
let rt = Builder::new_current_thread()
.enable_all()
.on_thread_park(move || {
if !woken2.swap(tru... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common_before_park.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common_before_park.rs | 41 | 92 |
tokio-rs/tokio:tokio/tests/rt_common_before_park.rs:3 | std::thread::sleep(std::time::Duration::from_millis(5));
handle.block_on(async move {
notify2.notify_one();
});
});
rt.block_on(async {
notify.notified().await;
});
th.join().unwrap();
} | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_common_before_park.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/tests/rt_common_before_park.rs | 81 | 92 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:1 | #![warn(rust_2018_idioms)]
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio_test::{assert_err, assert_ok};
use std::thread;
use std::time::Duration;
#[test]
fn spawned_task_does_not_progress_without_block_on() {
let (tx, mut rx) = oneshot::channel();
let mut rt = rt();
rt.spawn(async mo... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | e19bd77ef0149b3141981b36f3ebc442fae4a0b4 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e19bd77ef0149b3141981b36f3ebc442fae4a0b4/tokio/tests/rt_current_thread.rs | 1 | 34 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:1 | #![warn(rust_2018_idioms)]
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio::timer;
use tokio_test::{assert_err, assert_ok};
use futures_util::future::poll_fn;
use std::sync::{mpsc, Arc};
use std::task::Poll;
use std::thread;
use std::ti... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 1 | 60 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:2 | });
assert_eq!(out, "ZOMG");
}
#[test]
fn spawn_one() {
let mut 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_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 41 | 100 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:3 | });
assert_eq!(out, "ZOMG");
}
#[test]
fn spawn_many() {
use tokio::sync::mpsc;
const ITER: usize = 10;
let mut rt = rt();
let out = rt.block_on(async {
let (done_tx, mut done_rx) = mpsc::unbounded_channel();
let mut txs = (0..ITER)
.map(|i| {
let (t... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 81 | 140 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:4 | 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 outstanding_tasks_dropped() {
let mut rt = rt();
let cnt = Arc::new(());
rt.bl... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 121 | 180 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:6 | 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;
}
});
thread::spawn(move || {
thread::s... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 201 | 260 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:7 | });
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 {
timer::delay_for(dur).await;
});
assert!(now.elapsed() >= dur);
}
#[test]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:8 | }
#[test]
fn client_server_block_on() {
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());
}
async fn yield_once() {
let mut yielded = false;
poll_fn(|cx| {
if yielded {
... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 281 | 337 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:9 | });
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();
}
fn rt() -> Runtime {
tokio::runtime::Builder::new()
.current_thread()
.build()
.unwrap(... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | c8fdbed27a23321bb149a45aad5910d32c24be2c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c8fdbed27a23321bb149a45aad5910d32c24be2c/tokio/tests/rt_current_thread.rs | 321 | 337 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:7 | });
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 {
timer::delay_for(dur).await;
});
assert!(now.elapsed() >= dur);
}
#[test]... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | d70c928d88dff9e3e8d673b8ee02bce131598550 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d70c928d88dff9e3e8d673b8ee02bce131598550/tokio/tests/rt_current_thread.rs | 241 | 300 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:8 | }
#[test]
fn client_server_block_on() {
let _ = env_logger::try_init();
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());
}
async fn yield_once() {
let mut yielded = false;
p... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | d70c928d88dff9e3e8d673b8ee02bce131598550 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d70c928d88dff9e3e8d673b8ee02bce131598550/tokio/tests/rt_current_thread.rs | 281 | 339 |
tokio-rs/tokio:tokio/tests/rt_current_thread.rs:9 | // 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();
}
fn rt() -> Runtime {
tokio::runtime::... | rust | rust | testsuite | tokio-rs/tokio | tokio/tests/rt_current_thread.rs | MIT | d70c928d88dff9e3e8d673b8ee02bce131598550 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d70c928d88dff9e3e8d673b8ee02bce131598550/tokio/tests/rt_current_thread.rs | 321 | 339 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.