re-enable tests if io_uring is enabled

This commit is contained in:
wireless4024 2023-02-12 10:09:53 +07:00
parent e8bb559e64
commit a6791f105c
No known key found for this signature in database
GPG Key ID: D102C2A868192A39
1 changed files with 62 additions and 10 deletions

View File

@ -4,7 +4,7 @@ use std::{
}; };
use actix_rt::{task::JoinError, Arbiter, System}; use actix_rt::{task::JoinError, Arbiter, System};
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
use { use {
std::{sync::mpsc::channel, thread}, std::{sync::mpsc::channel, thread},
tokio::sync::oneshot, tokio::sync::oneshot,
@ -23,7 +23,7 @@ fn await_for_timer() {
); );
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn run_with_code() { fn run_with_code() {
let sys = System::new(); let sys = System::new();
@ -117,7 +117,7 @@ fn wait_for_spawns() {
// Temporary disabled tests for io-uring feature. // Temporary disabled tests for io-uring feature.
// They should be enabled when possible. // They should be enabled when possible.
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn arbiter_spawn_fn_runs() { fn arbiter_spawn_fn_runs() {
let _ = System::new(); let _ = System::new();
@ -134,7 +134,7 @@ fn arbiter_spawn_fn_runs() {
arbiter.join().unwrap(); arbiter.join().unwrap();
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn arbiter_handle_spawn_fn_runs() { fn arbiter_handle_spawn_fn_runs() {
let sys = System::new(); let sys = System::new();
@ -157,7 +157,7 @@ fn arbiter_handle_spawn_fn_runs() {
sys.run().unwrap(); sys.run().unwrap();
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn arbiter_drop_no_panic_fn() { fn arbiter_drop_no_panic_fn() {
let _ = System::new(); let _ = System::new();
@ -169,7 +169,7 @@ fn arbiter_drop_no_panic_fn() {
arbiter.join().unwrap(); arbiter.join().unwrap();
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn arbiter_drop_no_panic_fut() { fn arbiter_drop_no_panic_fut() {
let _ = System::new(); let _ = System::new();
@ -181,11 +181,10 @@ fn arbiter_drop_no_panic_fut() {
arbiter.join().unwrap(); arbiter.join().unwrap();
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn system_arbiter_spawn() { fn system_arbiter_spawn() {
let runner = System::new(); let runner = System::new();
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
let sys = System::current(); let sys = System::current();
@ -212,7 +211,7 @@ fn system_arbiter_spawn() {
thread.join().unwrap(); thread.join().unwrap();
} }
#[cfg(not(feature = "io-uring"))] //#[cfg(not(feature = "io-uring"))]
#[test] #[test]
fn system_stop_stops_arbiters() { fn system_stop_stops_arbiters() {
let sys = System::new(); let sys = System::new();
@ -267,6 +266,29 @@ fn new_system_with_tokio() {
assert_eq!(res, 123); assert_eq!(res, 123);
assert_eq!(rx.recv().unwrap(), 42); assert_eq!(rx.recv().unwrap(), 42);
} }
#[cfg(feature = "io-uring")]
#[test]
fn new_system_with_tokio() {
let (tx, rx) = channel();
let res = System::with_tokio_rt(move || {
tokio_uring::Runtime::new(&tokio_uring::builder()).unwrap()
})
.block_on(async {
actix_rt::time::sleep(Duration::from_millis(1)).await;
tokio::task::spawn(async move {
tx.send(42).unwrap();
})
.await
.unwrap();
123usize
});
assert_eq!(res, 123);
assert_eq!(rx.recv().unwrap(), 42);
}
#[cfg(not(feature = "io-uring"))] #[cfg(not(feature = "io-uring"))]
#[test] #[test]
@ -301,6 +323,36 @@ fn new_arbiter_with_tokio() {
assert!(!counter.load(Ordering::SeqCst)); assert!(!counter.load(Ordering::SeqCst));
} }
#[cfg(feature = "io-uring")]
#[test]
fn new_arbiter_with_tokio() {
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
let _ = System::new();
let arb = Arbiter::with_tokio_rt(|| {
tokio_uring::Runtime::new(&tokio_uring::builder()).unwrap()
});
let counter = Arc::new(AtomicBool::new(true));
let counter1 = counter.clone();
let did_spawn = arb.spawn(async move {
actix_rt::time::sleep(Duration::from_millis(1)).await;
counter1.store(false, Ordering::SeqCst);
Arbiter::current().stop();
});
assert!(did_spawn);
arb.join().unwrap();
assert!(!counter.load(Ordering::SeqCst));
}
#[test] #[test]
#[should_panic] #[should_panic]
fn no_system_current_panic() { fn no_system_current_panic() {
@ -351,7 +403,7 @@ fn spawn_local() {
#[test] #[test]
fn tokio_uring_arbiter() { fn tokio_uring_arbiter() {
System::new().block_on(async { System::new().block_on(async {
let (tx, rx) = std::sync::mpsc::channel(); let (tx, rx) = channel();
Arbiter::new().spawn(async move { Arbiter::new().spawn(async move {
let handle = actix_rt::spawn(async move { let handle = actix_rt::spawn(async move {