1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

upgrade: tokio 0.1 in test_util crate (#8885)

This commit upgrades "tokio" and crates from tokio
ecosystem in "test_util" crate.
This commit is contained in:
Yosi Pramajaya 2021-01-10 19:20:47 +07:00 committed by GitHub
parent 4361895476
commit 9e9e104664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 285 additions and 79 deletions

284
Cargo.lock generated
View file

@ -104,6 +104,27 @@ dependencies = [
"pin-project-lite 0.1.7",
]
[[package]]
name = "async-stream"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c"
dependencies = [
"async-stream-impl",
"futures-core",
]
[[package]]
name = "async-stream-impl"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.7",
"syn 1.0.56",
]
[[package]]
name = "async-trait"
version = "0.1.42"
@ -156,6 +177,12 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
[[package]]
name = "base64"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bitflags"
version = "1.2.1"
@ -222,6 +249,12 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0dcbc35f504eb6fc275a6d20e4ebcda18cf50d40ba6fabff8c711fa16cb3b16"
[[package]]
name = "bytes"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72"
[[package]]
name = "cargo_gn"
version = "0.0.15"
@ -297,7 +330,7 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25e4c606eb459dd29f7c57b2e0879f2b6f14ee130918c2b78ccb58a9624e6c7a"
dependencies = [
"getrandom",
"getrandom 0.1.15",
"proc-macro-hack",
]
@ -451,7 +484,7 @@ dependencies = [
"termcolor",
"test_util",
"tokio 0.2.22",
"tokio-rustls",
"tokio-rustls 0.14.1",
"tower-test",
"uuid",
"walkdir",
@ -483,7 +516,7 @@ name = "deno_crypto"
version = "0.9.0"
dependencies = [
"deno_core",
"rand",
"rand 0.7.3",
]
[[package]]
@ -545,7 +578,7 @@ dependencies = [
"filetime",
"fwdansi",
"http",
"hyper",
"hyper 0.13.9",
"indexmap",
"lazy_static",
"libc",
@ -563,7 +596,7 @@ dependencies = [
"termcolor",
"test_util",
"tokio 0.2.22",
"tokio-rustls",
"tokio-rustls 0.14.1",
"uuid",
"webpki",
"webpki-roots",
@ -589,8 +622,8 @@ dependencies = [
"http",
"serde",
"tokio 0.2.22",
"tokio-rustls",
"tokio-tungstenite",
"tokio-rustls 0.14.1",
"tokio-tungstenite 0.11.0",
"webpki",
"webpki-roots",
]
@ -1025,6 +1058,17 @@ dependencies = [
"wasi 0.9.0+wasi-snapshot-preview1",
]
[[package]]
name = "getrandom"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4060f4657be78b8e766215b02b18a2e862d83745545de804638e2b545e81aee6"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
]
[[package]]
name = "h2"
version = "0.2.6"
@ -1089,6 +1133,16 @@ dependencies = [
"http",
]
[[package]]
name = "http-body"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994"
dependencies = [
"bytes 1.0.0",
"http",
]
[[package]]
name = "httparse"
version = "1.3.4"
@ -1122,7 +1176,7 @@ dependencies = [
"futures-util",
"h2",
"http",
"http-body",
"http-body 0.3.1",
"httparse",
"httpdate",
"itoa",
@ -1134,6 +1188,29 @@ dependencies = [
"want",
]
[[package]]
name = "hyper"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe"
dependencies = [
"bytes 1.0.0",
"futures-channel",
"futures-core",
"futures-util",
"http",
"http-body 0.4.0",
"httparse",
"httpdate",
"itoa",
"pin-project 1.0.2",
"socket2",
"tokio 1.0.1",
"tower-service",
"tracing",
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.21.0"
@ -1142,11 +1219,11 @@ checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6"
dependencies = [
"bytes 0.5.6",
"futures-util",
"hyper",
"hyper 0.13.9",
"log",
"rustls",
"rustls 0.18.1",
"tokio 0.2.22",
"tokio-rustls",
"tokio-rustls 0.14.1",
"webpki",
]
@ -1212,6 +1289,15 @@ dependencies = [
"bytes 0.5.6",
]
[[package]]
name = "input_buffer"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413"
dependencies = [
"bytes 1.0.0",
]
[[package]]
name = "instant"
version = "0.1.9"
@ -1698,7 +1784,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
dependencies = [
"phf_shared",
"rand",
"rand 0.7.3",
]
[[package]]
@ -1905,14 +1991,26 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"getrandom 0.1.15",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc 0.2.0",
"rand_pcg",
]
[[package]]
name = "rand"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c24fcd450d3fa2b592732565aa4f17a27a61c65ece4726353e000939b0edee34"
dependencies = [
"libc",
"rand_chacha 0.3.0",
"rand_core 0.6.1",
"rand_hc 0.3.0",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
@ -1920,7 +2018,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
"rand_core 0.5.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core 0.6.1",
]
[[package]]
@ -1929,7 +2037,16 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
"getrandom 0.1.15",
]
[[package]]
name = "rand_core"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5"
dependencies = [
"getrandom 0.2.1",
]
[[package]]
@ -1938,7 +2055,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
"rand_core 0.5.1",
]
[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core 0.6.1",
]
[[package]]
@ -1947,7 +2073,7 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
dependencies = [
"rand_core",
"rand_core 0.5.1",
]
[[package]]
@ -2002,8 +2128,8 @@ dependencies = [
"futures-core",
"futures-util",
"http",
"http-body",
"hyper",
"http-body 0.3.1",
"hyper 0.13.9",
"hyper-rustls",
"ipnet",
"js-sys",
@ -2013,11 +2139,11 @@ dependencies = [
"mime_guess",
"percent-encoding",
"pin-project-lite 0.1.7",
"rustls",
"rustls 0.18.1",
"serde",
"serde_urlencoded",
"tokio 0.2.22",
"tokio-rustls",
"tokio-rustls 0.14.1",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -2069,6 +2195,19 @@ dependencies = [
"webpki",
]
[[package]]
name = "rustls"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b"
dependencies = [
"base64 0.13.0",
"log",
"ring",
"sct",
"webpki",
]
[[package]]
name = "rusty_v8"
version = "0.15.0"
@ -2746,7 +2885,7 @@ checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
dependencies = [
"cfg-if 0.1.10",
"libc",
"rand",
"rand 0.7.3",
"redox_syscall",
"remove_dir_all",
"winapi 0.3.9",
@ -2774,17 +2913,18 @@ dependencies = [
name = "test_util"
version = "0.1.0"
dependencies = [
"bytes 0.5.6",
"async-stream",
"bytes 1.0.0",
"futures",
"hyper",
"hyper 0.14.2",
"lazy_static",
"os_pipe",
"pty",
"regex",
"tempfile",
"tokio 0.2.22",
"tokio-rustls",
"tokio-tungstenite",
"tokio 1.0.1",
"tokio-rustls 0.22.0",
"tokio-tungstenite 0.13.0",
]
[[package]]
@ -2888,6 +3028,26 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "tokio"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd"
dependencies = [
"autocfg",
"bytes 1.0.0",
"libc",
"memchr",
"mio 0.7.6",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite 0.2.0",
"signal-hook-registry",
"tokio-macros 1.0.0",
"winapi 0.3.9",
]
[[package]]
name = "tokio-macros"
version = "0.2.5"
@ -2910,6 +3070,17 @@ dependencies = [
"syn 1.0.56",
]
[[package]]
name = "tokio-macros"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494"
dependencies = [
"proc-macro2 1.0.24",
"quote 1.0.7",
"syn 1.0.56",
]
[[package]]
name = "tokio-rustls"
version = "0.14.1"
@ -2917,11 +3088,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a"
dependencies = [
"futures-core",
"rustls",
"rustls 0.18.1",
"tokio 0.2.22",
"webpki",
]
[[package]]
name = "tokio-rustls"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6"
dependencies = [
"rustls 0.19.0",
"tokio 1.0.1",
"webpki",
]
[[package]]
name = "tokio-test"
version = "0.2.1"
@ -2943,7 +3125,20 @@ dependencies = [
"log",
"pin-project 0.4.23",
"tokio 0.2.22",
"tungstenite",
"tungstenite 0.11.1",
]
[[package]]
name = "tokio-tungstenite"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b"
dependencies = [
"futures-util",
"log",
"pin-project 1.0.2",
"tokio 1.0.1",
"tungstenite 0.12.0",
]
[[package]]
@ -3032,9 +3227,28 @@ dependencies = [
"bytes 0.5.6",
"http",
"httparse",
"input_buffer",
"input_buffer 0.3.1",
"log",
"rand",
"rand 0.7.3",
"sha-1",
"url",
"utf-8",
]
[[package]]
name = "tungstenite"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24"
dependencies = [
"base64 0.13.0",
"byteorder",
"bytes 1.0.0",
"http",
"httparse",
"input_buffer 0.4.0",
"log",
"rand 0.8.1",
"sha-1",
"url",
"utf-8",
@ -3134,7 +3348,7 @@ version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
dependencies = [
"rand",
"rand 0.7.3",
]
[[package]]

View file

@ -12,16 +12,17 @@ name = "test_server"
path = "src/test_server.rs"
[dependencies]
tokio = { version = "0.2.22", features = ["full"] }
futures = "0.3.8"
bytes = "0.5.6"
tokio = { version = "1.0", features = ["full"] }
futures = "0.3"
bytes = "1"
lazy_static = "1.4.0"
os_pipe = "0.9.2"
os_pipe = "0.9"
regex = "1.3.9"
tempfile = "3.1.0"
hyper = "0.13"
tokio-tungstenite = "0.11"
tokio-rustls = "0.14"
hyper = { version = "0.14.2", features = ["server", "http1", "runtime"] }
tokio-tungstenite = "0.13"
tokio-rustls = "0.22"
async-stream = "0.3.0"
[target.'cfg(unix)'.dependencies]
pty = "0.2.2"

View file

@ -5,28 +5,28 @@
#[macro_use]
extern crate lazy_static;
use core::mem::replace;
use futures::FutureExt;
use futures::Stream;
use futures::StreamExt;
use futures::TryStreamExt;
use hyper::header::HeaderValue;
use hyper::server::Server;
use hyper::service::make_service_fn;
use hyper::service::service_fn;
use hyper::Body;
use hyper::Request;
use hyper::Response;
use hyper::Server;
use hyper::StatusCode;
use os_pipe::pipe;
#[cfg(unix)]
pub use pty;
use regex::Regex;
use std::collections::HashMap;
use std::convert::Infallible;
use std::env;
use std::io;
use std::io::Read;
use std::io::Write;
use std::mem::replace;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::pin::Pin;
@ -146,11 +146,9 @@ async fn hyper_hello(port: u16) {
println!("hyper hello");
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let hello_svc = make_service_fn(|_| async move {
Ok::<_, hyper::error::Error>(service_fn(
move |_: Request<Body>| async move {
Ok::<_, hyper::error::Error>(Response::new(Body::from("Hello World!")))
},
))
Ok::<_, Infallible>(service_fn(move |_: Request<Body>| async move {
Ok::<_, Infallible>(Response::new(Body::from("Hello World!")))
}))
});
let server = Server::bind(&addr).serve(hello_svc);
@ -203,7 +201,7 @@ async fn another_redirect(req: Request<Body>) -> hyper::Result<Response<Body>> {
}
async fn run_ws_server(addr: &SocketAddr) {
let mut listener = TcpListener::bind(addr).await.unwrap();
let listener = TcpListener::bind(addr).await.unwrap();
while let Ok((stream, _addr)) = listener.accept().await {
tokio::spawn(async move {
let ws_stream_fut = accept_async(stream);
@ -278,7 +276,7 @@ async fn run_wss_server(addr: &SocketAddr) {
let tls_config = get_tls_config(cert_file, key_file).await.unwrap();
let tls_acceptor = TlsAcceptor::from(tls_config);
let mut listener = TcpListener::bind(addr).await.unwrap();
let listener = TcpListener::bind(addr).await.unwrap();
while let Ok((stream, _addr)) = listener.accept().await {
let acceptor = tls_acceptor.clone();
@ -620,7 +618,7 @@ unsafe impl std::marker::Send for HyperAcceptor<'_> {}
async fn wrap_redirect_server() {
let redirect_svc =
make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(redirect)) });
make_service_fn(|_| async { Ok::<_, Infallible>(service_fn(redirect)) });
let redirect_addr = SocketAddr::from(([127, 0, 0, 1], REDIRECT_PORT));
let redirect_server = Server::bind(&redirect_addr).serve(redirect_svc);
if let Err(e) = redirect_server.await {
@ -630,7 +628,7 @@ async fn wrap_redirect_server() {
async fn wrap_double_redirect_server() {
let double_redirects_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(double_redirects))
Ok::<_, Infallible>(service_fn(double_redirects))
});
let double_redirects_addr =
SocketAddr::from(([127, 0, 0, 1], DOUBLE_REDIRECTS_PORT));
@ -643,7 +641,7 @@ async fn wrap_double_redirect_server() {
async fn wrap_inf_redirect_server() {
let inf_redirects_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(inf_redirects))
Ok::<_, Infallible>(service_fn(inf_redirects))
});
let inf_redirects_addr =
SocketAddr::from(([127, 0, 0, 1], INF_REDIRECTS_PORT));
@ -656,7 +654,7 @@ async fn wrap_inf_redirect_server() {
async fn wrap_another_redirect_server() {
let another_redirect_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(another_redirect))
Ok::<_, Infallible>(service_fn(another_redirect))
});
let another_redirect_addr =
SocketAddr::from(([127, 0, 0, 1], ANOTHER_REDIRECT_PORT));
@ -669,7 +667,7 @@ async fn wrap_another_redirect_server() {
async fn wrap_abs_redirect_server() {
let abs_redirect_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(absolute_redirect))
Ok::<_, Infallible>(service_fn(absolute_redirect))
});
let abs_redirect_addr =
SocketAddr::from(([127, 0, 0, 1], REDIRECT_ABSOLUTE_PORT));
@ -681,9 +679,8 @@ async fn wrap_abs_redirect_server() {
}
async fn wrap_main_server() {
let main_server_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(main_server))
});
let main_server_svc =
make_service_fn(|_| async { Ok::<_, Infallible>(service_fn(main_server)) });
let main_server_addr = SocketAddr::from(([127, 0, 0, 1], PORT));
let main_server = Server::bind(&main_server_addr).serve(main_server_svc);
if let Err(e) = main_server.await {
@ -698,29 +695,23 @@ async fn wrap_main_https_server() {
let tls_config = get_tls_config(cert_file, key_file)
.await
.expect("Cannot get TLS config");
let mut tcp = TcpListener::bind(&main_server_https_addr)
.await
.expect("Cannot bind TCP");
loop {
let tcp = TcpListener::bind(&main_server_https_addr)
.await
.expect("Cannot bind TCP");
let tls_acceptor = TlsAcceptor::from(tls_config.clone());
// Prepare a long-running future stream to accept and serve cients.
let incoming_tls_stream = tcp
.incoming()
.map_err(|e| {
eprintln!("Error Incoming: {:?}", e);
io::Error::new(io::ErrorKind::Other, e)
})
.and_then(move |s| {
use futures::TryFutureExt;
tls_acceptor.accept(s).map_err(|e| {
eprintln!("TLS Error {:?}", e);
e
})
})
.boxed();
let incoming_tls_stream = async_stream::stream! {
loop {
let (socket, _) = tcp.accept().await?;
let stream = tls_acceptor.accept(socket);
yield stream.await;
}
}
.boxed();
let main_server_https_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(main_server))
Ok::<_, Infallible>(service_fn(main_server))
});
let main_server_https = Server::builder(HyperAcceptor {
acceptor: incoming_tls_stream,
@ -737,7 +728,7 @@ async fn wrap_main_https_server() {
// Use the single-threaded scheduler. The hyper server is used as a point of
// comparison for the (single-threaded!) benchmarks in cli/bench. We're not
// comparing apples to apples if we use the default multi-threaded scheduler.
#[tokio::main(basic_scheduler)]
#[tokio::main(flavor = "current_thread")]
pub async fn run_all_servers() {
if let Some(port) = env::args().nth(1) {
return hyper_hello(port.parse::<u16>().unwrap()).await;