From 445fccb882c85ae86038b5961910afa1564d42d8 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Mon, 5 Aug 2024 10:19:50 +0800 Subject: [PATCH] Test: fix CI tests --- cluster_benchmark/tests/benchmark/store/test.rs | 4 ++-- examples/raft-kv-memstore/src/test.rs | 4 ++-- openraft/src/testing/runtime/mod.rs | 4 ++-- .../async_runtime/tokio_impls/tokio_runtime.rs | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cluster_benchmark/tests/benchmark/store/test.rs b/cluster_benchmark/tests/benchmark/store/test.rs index 830f9694d..cc8665628 100644 --- a/cluster_benchmark/tests/benchmark/store/test.rs +++ b/cluster_benchmark/tests/benchmark/store/test.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use openraft::testing::StoreBuilder; -use openraft::testing::Suite; +use openraft::testing::log::StoreBuilder; +use openraft::testing::log::Suite; use openraft::StorageError; use crate::store::LogStore; diff --git a/examples/raft-kv-memstore/src/test.rs b/examples/raft-kv-memstore/src/test.rs index 1a32ea0d2..289fb256c 100644 --- a/examples/raft-kv-memstore/src/test.rs +++ b/examples/raft-kv-memstore/src/test.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use openraft::testing::StoreBuilder; -use openraft::testing::Suite; +use openraft::testing::log::StoreBuilder; +use openraft::testing::log::Suite; use openraft::StorageError; use crate::store::LogStore; diff --git a/openraft/src/testing/runtime/mod.rs b/openraft/src/testing/runtime/mod.rs index 4c6a127ca..c84d1ceb1 100644 --- a/openraft/src/testing/runtime/mod.rs +++ b/openraft/src/testing/runtime/mod.rs @@ -179,7 +179,7 @@ impl Suite { for idx in 0..n_senders { let tx = Arc::clone(&tx); // no need to wait for senders here, we wait by recv()ing - let _ = Rt::spawn(async move { + let _handle = Rt::spawn(async move { tx.send(idx).unwrap(); }); } @@ -292,7 +292,7 @@ impl Suite { let number_to_send = 1; let (tx, rx) = Rt::Oneshot::channel::(); // no need to join the task, this test only works iff the sender task finishes its job - let _ = Rt::spawn(async move { + let _handle = Rt::spawn(async move { tx.send(number_to_send).unwrap(); }); let number_received = rx.await.unwrap(); diff --git a/openraft/src/type_config/async_runtime/tokio_impls/tokio_runtime.rs b/openraft/src/type_config/async_runtime/tokio_impls/tokio_runtime.rs index e94b1464d..b79b8084e 100644 --- a/openraft/src/type_config/async_runtime/tokio_impls/tokio_runtime.rs +++ b/openraft/src/type_config/async_runtime/tokio_impls/tokio_runtime.rs @@ -222,7 +222,8 @@ mod tests { use crate::testing::runtime::Suite; #[test] - fn test_tokio_rt() { + #[cfg(not(feature = "singlethreaded"))] + fn test_tokio_rt_not_singlethreaded() { let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(8) .enable_all() @@ -231,4 +232,18 @@ mod tests { rt.block_on(Suite::::test_all()); } + + #[test] + #[cfg(feature = "singlethreaded")] + fn test_tokio_rt_singlethreaded() { + let rt = tokio::runtime::Builder::new_multi_thread() + .worker_threads(8) + .enable_all() + .build() + .expect("Failed building the runtime"); + // `spawn_local` needs to be called called from inside of a `task::LocalSet` + let local = tokio::task::LocalSet::new(); + + local.block_on(&rt, Suite::::test_all()); + } }