executor work

This commit is contained in:
John Smith
2022-06-27 23:46:29 -04:00
parent ebea72c9db
commit fdbb4c6397
59 changed files with 726 additions and 640 deletions

View File

@@ -69,53 +69,64 @@ pub fn run_all_tests() {
info!("Finished unit tests");
}
#[cfg(feature = "rt-tokio")]
fn block_on<F: Future<Output = T>, T>(f: F) -> T {
let rt = tokio::runtime::Runtime::new().unwrap();
let local = tokio::task::LocalSet::new();
local.block_on(&rt, f)
}
#[cfg(feature = "rt-async-std")]
fn block_on<F: Future<Output = T>, T>(f: F) -> T {
async_std::task::block_on(f)
}
fn exec_test_host_interface() {
async_std::task::block_on(async {
block_on(async {
test_host_interface::test_all().await;
});
}
fn exec_test_dht_key() {
async_std::task::block_on(async {
block_on(async {
test_dht_key::test_all().await;
});
}
fn exec_test_veilid_core() {
async_std::task::block_on(async {
block_on(async {
test_veilid_core::test_all().await;
});
}
fn exec_test_veilid_config() {
async_std::task::block_on(async {
block_on(async {
test_veilid_config::test_all().await;
})
}
fn exec_test_async_peek_stream() {
async_std::task::block_on(async {
block_on(async {
test_async_peek_stream::test_all().await;
})
}
fn exec_test_connection_table() {
async_std::task::block_on(async {
block_on(async {
test_connection_table::test_all().await;
})
}
fn exec_test_table_store() {
async_std::task::block_on(async {
block_on(async {
test_table_store::test_all().await;
})
}
fn exec_test_protected_store() {
async_std::task::block_on(async {
block_on(async {
test_protected_store::test_all().await;
})
}
fn exec_test_crypto() {
async_std::task::block_on(async {
block_on(async {
test_crypto::test_all().await;
})
}
fn exec_test_envelope_receipt() {
async_std::task::block_on(async {
block_on(async {
test_envelope_receipt::test_all().await;
})
}

View File

@@ -1,7 +1,17 @@
use super::*;
use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::FutureExt;
use async_std::task;
cfg_if! {
if #[cfg(feature="rt-async-std")] {
use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::FutureExt;
use async_std::task::sleep;
} else if #[cfg(feature="rt-tokio")] {
use tokio::net::{TcpListener, TcpStream};
use tokio::time::sleep;
use tokio_util::compat::*;
}
}
use futures_util::{AsyncReadExt, AsyncWriteExt};
use std::io;
@@ -18,23 +28,40 @@ async fn make_tcp_loopback() -> Result<(TcpStream, TcpStream), io::Error> {
Result::<TcpStream, io::Error>::Ok(accepted_stream)
};
let connect_future = async {
task::sleep(Duration::from_secs(1)).await;
sleep(Duration::from_secs(1)).await;
let connected_stream = TcpStream::connect(local_addr).await?;
connected_stream.set_nodelay(true)?;
Result::<TcpStream, io::Error>::Ok(connected_stream)
};
Ok(accept_future.try_join(connect_future).await?)
cfg_if! {
if #[cfg(feature="rt-async-std")] {
accept_future.try_join(connect_future).await
} else if #[cfg(feature="rt-tokio")] {
tokio::try_join!(accept_future, connect_future)
}
}
}
async fn make_async_peek_stream_loopback() -> (AsyncPeekStream, AsyncPeekStream) {
let (acc, conn) = make_tcp_loopback().await.unwrap();
#[cfg(feature = "rt-tokio")]
let acc = acc.compat();
#[cfg(feature = "rt-tokio")]
let conn = conn.compat();
let aps_a = AsyncPeekStream::new(acc);
let aps_c = AsyncPeekStream::new(conn);
(aps_a, aps_c)
}
#[cfg(feature = "rt-tokio")]
async fn make_stream_loopback() -> (Compat<TcpStream>, Compat<TcpStream>) {
let (a, c) = make_tcp_loopback().await.unwrap();
(a.compat(), c.compat())
}
#[cfg(feature = "rt-async-std")]
async fn make_stream_loopback() -> (TcpStream, TcpStream) {
make_tcp_loopback().await.unwrap()
}