executor work
This commit is contained in:
		@@ -465,7 +465,8 @@ cfg_if! {
 | 
			
		||||
            let t1 = intf::get_timestamp();
 | 
			
		||||
            let mut interfaces = intf::utils::network_interfaces::NetworkInterfaces::new();
 | 
			
		||||
            let count = 100;
 | 
			
		||||
            for _ in 0..count {
 | 
			
		||||
            for x in 0..count {
 | 
			
		||||
                info!("loop {}", x);
 | 
			
		||||
                if let Err(e) = interfaces.refresh().await {
 | 
			
		||||
                    error!("error refreshing interfaces: {}", e);
 | 
			
		||||
                }
 | 
			
		||||
@@ -508,43 +509,6 @@ pub async fn test_get_random_u32() {
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn test_single_future() {
 | 
			
		||||
    info!("testing single future");
 | 
			
		||||
    let sf = SingleFuture::<u32>::new();
 | 
			
		||||
    assert_eq!(sf.check().await, Ok(None));
 | 
			
		||||
    assert_eq!(
 | 
			
		||||
        sf.single_spawn(async {
 | 
			
		||||
            intf::sleep(2000).await;
 | 
			
		||||
            69
 | 
			
		||||
        })
 | 
			
		||||
        .await,
 | 
			
		||||
        Ok((None, true))
 | 
			
		||||
    );
 | 
			
		||||
    assert_eq!(sf.check().await, Ok(None));
 | 
			
		||||
    assert_eq!(sf.single_spawn(async { panic!() }).await, Ok((None, false)));
 | 
			
		||||
    assert_eq!(sf.join().await, Ok(Some(69)));
 | 
			
		||||
    assert_eq!(
 | 
			
		||||
        sf.single_spawn(async {
 | 
			
		||||
            intf::sleep(1000).await;
 | 
			
		||||
            37
 | 
			
		||||
        })
 | 
			
		||||
        .await,
 | 
			
		||||
        Ok((None, true))
 | 
			
		||||
    );
 | 
			
		||||
    intf::sleep(2000).await;
 | 
			
		||||
    assert_eq!(
 | 
			
		||||
        sf.single_spawn(async {
 | 
			
		||||
            intf::sleep(1000).await;
 | 
			
		||||
            27
 | 
			
		||||
        })
 | 
			
		||||
        .await,
 | 
			
		||||
        Ok((Some(37), true))
 | 
			
		||||
    );
 | 
			
		||||
    intf::sleep(2000).await;
 | 
			
		||||
    assert_eq!(sf.join().await, Ok(Some(27)));
 | 
			
		||||
    assert_eq!(sf.check().await, Ok(None));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn test_must_join_single_future() {
 | 
			
		||||
    info!("testing must join single future");
 | 
			
		||||
    let sf = MustJoinSingleFuture::<u32>::new();
 | 
			
		||||
@@ -604,7 +568,6 @@ pub async fn test_all() {
 | 
			
		||||
    test_sleep().await;
 | 
			
		||||
    #[cfg(not(target_arch = "wasm32"))]
 | 
			
		||||
    test_network_interfaces().await;
 | 
			
		||||
    test_single_future().await;
 | 
			
		||||
    test_must_join_single_future().await;
 | 
			
		||||
    test_eventual().await;
 | 
			
		||||
    test_eventual_value().await;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
use super::test_veilid_config::*;
 | 
			
		||||
use crate::intf::*;
 | 
			
		||||
use crate::xx::*;
 | 
			
		||||
use crate::*;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
use super::test_veilid_config::*;
 | 
			
		||||
use crate::intf::*;
 | 
			
		||||
use crate::xx::*;
 | 
			
		||||
use crate::*;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user