Skip to content

Commit

Permalink
Test: revert the 'spawn' to properly use a spawn from tokio
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Griffon <anthony@griffon.one>
  • Loading branch information
Miaxos committed Feb 20, 2024
1 parent 9c9b3a5 commit cf7f71e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
3 changes: 2 additions & 1 deletion tests/tests/append_entries/t10_see_higher_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)?;
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(async move {
spawn(async move {
let res = n0
.client_write(ClientRequest {
client: "0".to_string(),
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/client_api/t11_client_reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(async move {
spawn(async move {
// This will block for ever
let _x = r.client_request_many(1, "foo", 1).await;
});
Expand Down
5 changes: 3 additions & 2 deletions tests/tests/client_api/t51_write_when_leader_quit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(async move {
spawn(async move {
let res = n0.client_write(ClientRequest::make_request("cli", 1)).await;
tx.send(res).unwrap();
});
Expand Down Expand Up @@ -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)?;
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(async move {
spawn(async move {
let res = n0.client_write(ClientRequest::make_request("cli", 1)).await;
tx.send(res).unwrap();
});
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/fixtures/runtime.rs
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion tests/tests/membership/t11_add_learner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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)?;
<TypeConfig as RaftTypeConfig>::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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ 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.
Expand Down Expand Up @@ -102,7 +100,7 @@ async fn concurrent_write_and_add_learner() -> Result<()> {
let r = router.clone();

let handle = {
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(
spawn(
async move {
r.add_learner(leader, 3).await.unwrap();
Ok::<(), anyhow::Error>(())
Expand Down
8 changes: 3 additions & 5 deletions tests/tests/membership/t30_commit_joint_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ 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].
Expand Down Expand Up @@ -67,7 +65,7 @@ async fn commit_joint_config_during_0_to_012() -> Result<()> {

tracing::info!(log_index, "--- changing cluster config, should timeout");

<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn({
spawn({
let router = router.clone();
async move {
let node = router.get_raft_handle(&0).unwrap();
Expand Down Expand Up @@ -127,7 +125,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.
<TypeConfig as RaftTypeConfig>::AsyncRuntime::spawn(
spawn(
async move {
let node = router.get_raft_handle(&0)?;
node.change_membership([2, 3, 4], false).await?;
Expand Down
6 changes: 2 additions & 4 deletions tests/tests/replication/t10_append_entries_partial_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -36,7 +34,7 @@ async fn append_entries_partial_success() -> Result<()> {
router.set_append_entries_quota(Some(quota));

let r = router.clone();
<TypeConfig as RaftTypeConfig>::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();
});
Expand Down

0 comments on commit cf7f71e

Please sign in to comment.