From 0e7ab5a70877d72407942a2639c2f24bca64a48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=82=8E=E6=B3=BC?= Date: Fri, 9 Dec 2022 23:28:55 +0800 Subject: [PATCH] Fix: workaround cargo leaking SSL_CERT_FILE issue On Linux: command `cargo run` pollutes environment variables: It leaks `SSL_CERT_FILE` and `SSL_CERT_DIR` to the testing sub progress it runs. Which cause `reqwest` spending ~50 ms loading the certificates for every RPC. We just extend the RPC timeout to work around. - Fix: #550 --- examples/raft-kv-memstore/src/client.rs | 2 +- examples/raft-kv-memstore/src/lib.rs | 9 ++++++++- examples/raft-kv-memstore/tests/cluster/test_cluster.rs | 2 +- openraft/src/core/raft_core.rs | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/raft-kv-memstore/src/client.rs b/examples/raft-kv-memstore/src/client.rs index f730794ae..9bc817aac 100644 --- a/examples/raft-kv-memstore/src/client.rs +++ b/examples/raft-kv-memstore/src/client.rs @@ -170,7 +170,7 @@ impl ExampleClient { } .send(); - let res = timeout(Duration::from_millis(500), fu).await; + let res = timeout(Duration::from_millis(3_000), fu).await; let resp = match res { Ok(x) => x.map_err(|e| RPCError::Network(NetworkError::new(&e)))?, Err(timeout_err) => { diff --git a/examples/raft-kv-memstore/src/lib.rs b/examples/raft-kv-memstore/src/lib.rs index 7939b102a..f42b28922 100644 --- a/examples/raft-kv-memstore/src/lib.rs +++ b/examples/raft-kv-memstore/src/lib.rs @@ -36,7 +36,14 @@ pub type ExampleRaft = Raft pub async fn start_example_raft_node(node_id: ExampleNodeId, http_addr: String) -> std::io::Result<()> { // Create a configuration for the raft instance. - let config = Arc::new(Config::default().validate().unwrap()); + let config = Config { + heartbeat_interval: 500, + election_timeout_min: 1500, + election_timeout_max: 3000, + ..Default::default() + }; + + let config = Arc::new(config.validate().unwrap()); // Create a instance of where the Raft data will be stored. let store = Arc::new(ExampleStore::default()); diff --git a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs index 9fb28b9fa..521209e64 100644 --- a/examples/raft-kv-memstore/tests/cluster/test_cluster.rs +++ b/examples/raft-kv-memstore/tests/cluster/test_cluster.rs @@ -209,7 +209,7 @@ async fn test_cluster() -> anyhow::Result<()> { println!("=== change-membership to 3, "); let _x = client.change_membership(&btreeset! {3}).await?; - tokio::time::sleep(Duration::from_millis(1_000)).await; + tokio::time::sleep(Duration::from_millis(8_000)).await; println!("=== metrics after change-membership to {{3}}"); let x = client.metrics().await?; diff --git a/openraft/src/core/raft_core.rs b/openraft/src/core/raft_core.rs index aec5ac483..b0921b7a5 100644 --- a/openraft/src/core/raft_core.rs +++ b/openraft/src/core/raft_core.rs @@ -1408,8 +1408,8 @@ impl, S: RaftStorage> RaftCore