diff --git a/tests/tests/append_entries/t10_see_higher_vote.rs b/tests/tests/append_entries/t10_see_higher_vote.rs index cf883e5d7..9652f47c4 100644 --- a/tests/tests/append_entries/t10_see_higher_vote.rs +++ b/tests/tests/append_entries/t10_see_higher_vote.rs @@ -18,6 +18,7 @@ use openraft_memstore::ClientRequest; use openraft_memstore::TypeConfig; use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; /// A leader reverts to follower if a higher vote is seen when append-entries. @@ -68,7 +69,7 @@ async fn append_sees_higher_vote() -> Result<()> { router.wait(&0, timeout()).state(ServerState::Leader, "node-0 is leader").await?; let n0 = router.get_raft_handle(&0)?; - ::AsyncRuntime::spawn(async move { + spawn(async move { let res = n0 .client_write(ClientRequest { client: "0".to_string(), diff --git a/tests/tests/client_api/t11_client_reads.rs b/tests/tests/client_api/t11_client_reads.rs index 64b169227..3dc4f3b9d 100644 --- a/tests/tests/client_api/t11_client_reads.rs +++ b/tests/tests/client_api/t11_client_reads.rs @@ -14,6 +14,7 @@ use openraft::RaftTypeConfig; use openraft_memstore::TypeConfig; use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RPCRequest; use crate::fixtures::RaftRouter; @@ -165,7 +166,7 @@ async fn get_read_log_id() -> Result<()> { router.set_rpc_pre_hook(RPCTypes::AppendEntries, block_to_n0); let r = router.clone(); - ::AsyncRuntime::spawn(async move { + spawn(async move { // This will block for ever let _x = r.client_request_many(1, "foo", 1).await; }); diff --git a/tests/tests/client_api/t51_write_when_leader_quit.rs b/tests/tests/client_api/t51_write_when_leader_quit.rs index fcdeb3515..9d972477a 100644 --- a/tests/tests/client_api/t51_write_when_leader_quit.rs +++ b/tests/tests/client_api/t51_write_when_leader_quit.rs @@ -18,6 +18,7 @@ use openraft_memstore::TypeConfig; use crate::fixtures::init_default_ut_tracing; use crate::fixtures::runtime::oneshot; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; /// Client write will receive a [`ForwardToLeader`] error because of log reversion, when leader @@ -51,7 +52,7 @@ async fn write_when_leader_quit_and_log_revert() -> Result<()> { tracing::info!(log_index, "--- write a log in another task"); { let n0 = router.get_raft_handle(&0)?; - ::AsyncRuntime::spawn(async move { + spawn(async move { let res = n0.client_write(ClientRequest::make_request("cli", 1)).await; tx.send(res).unwrap(); }); @@ -125,7 +126,7 @@ async fn write_when_leader_switched() -> Result<()> { tracing::info!(log_index, "--- write a log in another task"); { let n0 = router.get_raft_handle(&0)?; - ::AsyncRuntime::spawn(async move { + spawn(async move { let res = n0.client_write(ClientRequest::make_request("cli", 1)).await; tx.send(res).unwrap(); }); diff --git a/tests/tests/fixtures/runtime.rs b/tests/tests/fixtures/runtime.rs index fd7b28f18..f727ef462 100644 --- a/tests/tests/fixtures/runtime.rs +++ b/tests/tests/fixtures/runtime.rs @@ -1,4 +1,6 @@ #![allow(unused_imports)] #[cfg(feature = "monoio")] pub use local_sync::oneshot; +#[cfg(feature = "monoio")] pub use monoio::spawn; +#[cfg(not(feature = "monoio"))] pub use tokio::spawn; #[cfg(not(feature = "monoio"))] pub use tokio::sync::oneshot; diff --git a/tests/tests/membership/t11_add_learner.rs b/tests/tests/membership/t11_add_learner.rs index d505e2f14..16476bb80 100644 --- a/tests/tests/membership/t11_add_learner.rs +++ b/tests/tests/membership/t11_add_learner.rs @@ -19,6 +19,7 @@ use openraft::StorageHelper; use openraft_memstore::TypeConfig; use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; #[async_entry::test(worker_threads = 8, init = "init_default_ut_tracing()", tracing_span = "debug")] @@ -214,7 +215,7 @@ async fn add_learner_when_previous_membership_not_committed() -> Result<()> { router.set_network_error(1, true); let node = router.get_raft_handle(&0)?; - ::AsyncRuntime::spawn(async move { + spawn(async move { let res = node.change_membership([0, 1], false).await; tracing::info!("do not expect res: {:?}", res); unreachable!("do not expect any res"); diff --git a/tests/tests/membership/t12_concurrent_write_and_add_learner.rs b/tests/tests/membership/t12_concurrent_write_and_add_learner.rs index 08e0c8cf6..c896cc53a 100644 --- a/tests/tests/membership/t12_concurrent_write_and_add_learner.rs +++ b/tests/tests/membership/t12_concurrent_write_and_add_learner.rs @@ -4,15 +4,16 @@ use std::time::Duration; use anyhow::Result; use maplit::btreeset; -use openraft::AsyncRuntime; + use openraft::Config; use openraft::LogIdOptionExt; -use openraft::RaftTypeConfig; + use openraft::ServerState; use openraft::Vote; -use openraft_memstore::TypeConfig; + use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; /// Cluster concurrent_write_and_add_learner test. @@ -102,7 +103,7 @@ async fn concurrent_write_and_add_learner() -> Result<()> { let r = router.clone(); let handle = { - ::AsyncRuntime::spawn( + spawn( async move { r.add_learner(leader, 3).await.unwrap(); Ok::<(), anyhow::Error>(()) diff --git a/tests/tests/membership/t30_commit_joint_config.rs b/tests/tests/membership/t30_commit_joint_config.rs index 1ca2087d1..c9cd57948 100644 --- a/tests/tests/membership/t30_commit_joint_config.rs +++ b/tests/tests/membership/t30_commit_joint_config.rs @@ -4,13 +4,14 @@ use std::time::Duration; use anyhow::Result; use futures::stream::StreamExt; use maplit::btreeset; -use openraft::AsyncRuntime; + use openraft::Config; use openraft::LogIdOptionExt; -use openraft::RaftTypeConfig; -use openraft_memstore::TypeConfig; + + use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; /// A leader must wait for learner to commit member-change from [0] to [0,1,2]. @@ -67,7 +68,7 @@ async fn commit_joint_config_during_0_to_012() -> Result<()> { tracing::info!(log_index, "--- changing cluster config, should timeout"); - ::AsyncRuntime::spawn({ + spawn({ let router = router.clone(); async move { let node = router.get_raft_handle(&0).unwrap(); @@ -127,7 +128,7 @@ async fn commit_joint_config_during_012_to_234() -> Result<()> { { let router = router.clone(); // this is expected to be blocked since 3 and 4 are isolated. - ::AsyncRuntime::spawn( + spawn( async move { let node = router.get_raft_handle(&0)?; node.change_membership([2, 3, 4], false).await?; diff --git a/tests/tests/replication/t10_append_entries_partial_success.rs b/tests/tests/replication/t10_append_entries_partial_success.rs index 925f40724..67de764f0 100644 --- a/tests/tests/replication/t10_append_entries_partial_success.rs +++ b/tests/tests/replication/t10_append_entries_partial_success.rs @@ -3,12 +3,10 @@ use std::time::Duration; use anyhow::Result; use maplit::btreeset; -use openraft::AsyncRuntime; use openraft::Config; -use openraft::RaftTypeConfig; -use openraft_memstore::TypeConfig; use crate::fixtures::init_default_ut_tracing; +use crate::fixtures::runtime::spawn; use crate::fixtures::RaftRouter; /// RaftNetwork::send_append_entries can return a partial success. @@ -36,7 +34,7 @@ async fn append_entries_partial_success() -> Result<()> { router.set_append_entries_quota(Some(quota)); let r = router.clone(); - ::AsyncRuntime::spawn(async move { + spawn(async move { // client request will be blocked due to limited quota=2 r.client_request_many(0, "0", n as usize).await.unwrap(); });