mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-17 18:27:49 +00:00
refactor: centralize ecstore rpc test runtime sources (#3818)
This commit is contained in:
@@ -143,7 +143,7 @@ mod tests {
|
||||
use tracing_subscriber::{Registry, layer::SubscriberExt};
|
||||
|
||||
fn ensure_test_rpc_secret() {
|
||||
let _ = rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET.set("test-rpc-secret".to_string());
|
||||
runtime_sources::ensure_test_rpc_secret();
|
||||
}
|
||||
|
||||
fn with_trace_parent<F>(trace_id_hex: &str, f: F)
|
||||
|
||||
@@ -164,6 +164,7 @@ pub fn verify_rpc_signature(url: &str, method: &Method, headers: &HeaderMap) ->
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::rpc::context_propagation::REQUEST_ID_HEADER;
|
||||
use crate::runtime_sources;
|
||||
use http::{HeaderMap, Method};
|
||||
use std::io::{self, Write};
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -215,7 +216,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn ensure_test_rpc_secret() {
|
||||
let _ = rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET.set("test-rpc-secret".to_string());
|
||||
runtime_sources::ensure_test_rpc_secret();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2220,7 +2220,7 @@ impl DiskAPI for RemoteDisk {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::rpc::internode_data_transport::{InternodeDataTransportCapabilities, TcpHttpInternodeDataTransport};
|
||||
use rustfs_common::GLOBAL_CONN_MAP;
|
||||
use crate::runtime_sources;
|
||||
use serde_json::Value;
|
||||
use std::io::{self as std_io, Write};
|
||||
use std::pin::Pin;
|
||||
@@ -2709,7 +2709,7 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn test_remote_disk_recovery_requires_disk_rpc_readiness() {
|
||||
init_tracing(Level::ERROR);
|
||||
let _ = rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET.set("test-rpc-secret".to_string());
|
||||
runtime_sources::ensure_test_rpc_secret();
|
||||
|
||||
let listener = match TcpListener::bind("127.0.0.1:0").await {
|
||||
Ok(listener) => listener,
|
||||
@@ -2737,8 +2737,8 @@ mod tests {
|
||||
health.mark_failure(&endpoint, "test_failure");
|
||||
assert_eq!(health.runtime_state(), RuntimeDriveHealthState::Offline);
|
||||
let channel = TonicEndpoint::from_shared(base_addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(base_addr.clone(), channel);
|
||||
assert!(GLOBAL_CONN_MAP.read().await.contains_key(&base_addr));
|
||||
runtime_sources::cache_test_node_channel(base_addr.clone(), channel).await;
|
||||
assert!(runtime_sources::test_node_channel_is_cached(&base_addr).await);
|
||||
|
||||
temp_env::async_with_vars(
|
||||
[
|
||||
@@ -2764,7 +2764,7 @@ mod tests {
|
||||
"a plain TCP listener without disk_info RPC readiness must not restore the remote disk online"
|
||||
);
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&base_addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&base_addr).await,
|
||||
"failed recovery probes should evict stale cached gRPC channels"
|
||||
);
|
||||
},
|
||||
@@ -3336,8 +3336,8 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let channel = TonicEndpoint::from_shared(addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.clone(), channel);
|
||||
assert!(GLOBAL_CONN_MAP.read().await.contains_key(&addr));
|
||||
runtime_sources::cache_test_node_channel(addr.clone(), channel).await;
|
||||
assert!(runtime_sources::test_node_channel_is_cached(&addr).await);
|
||||
|
||||
let _ = remote_disk
|
||||
.execute_with_timeout(
|
||||
@@ -3351,7 +3351,7 @@ mod tests {
|
||||
.expect_err("timeout should fail");
|
||||
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"timeout should evict cached connection"
|
||||
);
|
||||
}
|
||||
@@ -3380,7 +3380,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let channel = TonicEndpoint::from_shared(addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.clone(), channel);
|
||||
runtime_sources::cache_test_node_channel(addr.clone(), channel).await;
|
||||
|
||||
let err = remote_disk
|
||||
.execute_with_timeout(
|
||||
@@ -3407,7 +3407,7 @@ mod tests {
|
||||
"first timeout-like error should move the remote disk into suspect state"
|
||||
);
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"timeout-like errors should evict cached connection"
|
||||
);
|
||||
}
|
||||
@@ -3436,7 +3436,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let channel = TonicEndpoint::from_shared(addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.clone(), channel);
|
||||
runtime_sources::cache_test_node_channel(addr.clone(), channel).await;
|
||||
|
||||
let err = remote_disk
|
||||
.execute_with_timeout(
|
||||
@@ -3468,7 +3468,7 @@ mod tests {
|
||||
"first network-like error should move the remote disk into suspect state"
|
||||
);
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"network-like errors should evict cached connection"
|
||||
);
|
||||
}
|
||||
@@ -3497,7 +3497,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let channel = TonicEndpoint::from_shared(addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.clone(), channel);
|
||||
runtime_sources::cache_test_node_channel(addr.clone(), channel).await;
|
||||
|
||||
let err = remote_disk
|
||||
.execute_with_timeout_for_op_and_health_action(
|
||||
@@ -3521,7 +3521,7 @@ mod tests {
|
||||
"ignored network-like error should not mark remote disk faulty"
|
||||
);
|
||||
assert!(
|
||||
GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"ignored network-like error should not evict cached connection"
|
||||
);
|
||||
}
|
||||
@@ -3550,7 +3550,7 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let channel = TonicEndpoint::from_shared(addr.clone()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.clone(), channel);
|
||||
runtime_sources::cache_test_node_channel(addr.clone(), channel).await;
|
||||
|
||||
let err = remote_disk
|
||||
.execute_with_timeout(|| async { Err::<(), Error>(DiskError::FileNotFound) }, Duration::from_secs(1))
|
||||
@@ -3560,7 +3560,7 @@ mod tests {
|
||||
assert_eq!(err, DiskError::FileNotFound);
|
||||
assert!(remote_disk.is_online().await, "business errors should not mark remote disk faulty");
|
||||
assert!(
|
||||
GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"business errors should not evict cached connection"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ impl LockClient for RemoteClient {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rustfs_common::GLOBAL_CONN_MAP;
|
||||
use crate::runtime_sources;
|
||||
use rustfs_lock::{ObjectKey, types::LockPriority};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::task::JoinHandle;
|
||||
@@ -560,11 +560,11 @@ mod tests {
|
||||
|
||||
async fn cache_lazy_channel(addr: &str) {
|
||||
let channel = TonicEndpoint::from_shared(addr.to_string()).unwrap().connect_lazy();
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr.to_string(), channel);
|
||||
runtime_sources::cache_test_node_channel(addr.to_string(), channel).await;
|
||||
}
|
||||
|
||||
fn ensure_test_rpc_secret() {
|
||||
let _ = rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET.set("test-rpc-secret".to_string());
|
||||
runtime_sources::ensure_test_rpc_secret();
|
||||
}
|
||||
|
||||
fn test_lock_request(timeout_duration: Duration) -> LockRequest {
|
||||
@@ -581,7 +581,7 @@ mod tests {
|
||||
return;
|
||||
};
|
||||
cache_lazy_channel(&addr).await;
|
||||
assert!(GLOBAL_CONN_MAP.read().await.contains_key(&addr));
|
||||
assert!(runtime_sources::test_node_channel_is_cached(&addr).await);
|
||||
|
||||
temp_env::async_with_vars([(rustfs_config::ENV_OBJECT_LOCK_RPC_TIMEOUT_MS, Some("50"))], async {
|
||||
let client = RemoteClient::new(addr.clone());
|
||||
@@ -609,7 +609,7 @@ mod tests {
|
||||
response.error
|
||||
);
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"transport timeout should evict cached connection"
|
||||
);
|
||||
})
|
||||
@@ -626,7 +626,7 @@ mod tests {
|
||||
return;
|
||||
};
|
||||
cache_lazy_channel(&addr).await;
|
||||
assert!(GLOBAL_CONN_MAP.read().await.contains_key(&addr));
|
||||
assert!(runtime_sources::test_node_channel_is_cached(&addr).await);
|
||||
|
||||
temp_env::async_with_vars([(rustfs_config::ENV_OBJECT_LOCK_RPC_TIMEOUT_MS, Some("50"))], async {
|
||||
let client = RemoteClient::new(addr.clone());
|
||||
@@ -655,7 +655,7 @@ mod tests {
|
||||
responses[0].error
|
||||
);
|
||||
assert!(
|
||||
!GLOBAL_CONN_MAP.read().await.contains_key(&addr),
|
||||
!runtime_sources::test_node_channel_is_cached(&addr).await,
|
||||
"batch transport timeout should evict cached connection"
|
||||
);
|
||||
})
|
||||
|
||||
@@ -50,6 +50,9 @@ use tokio::sync::RwLock;
|
||||
use tonic::transport::Channel;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[cfg(test)]
|
||||
const TEST_RPC_SECRET: &str = "test-rpc-secret";
|
||||
|
||||
pub(crate) fn record_erasure_write_quorum_failure(stage: &'static str, dominant_error: &'static str) {
|
||||
global_internode_metrics().record_erasure_write_quorum_failure(stage, dominant_error);
|
||||
}
|
||||
@@ -165,6 +168,21 @@ pub(crate) async fn cached_node_channel(addr: &str) -> Option<Channel> {
|
||||
GLOBAL_CONN_MAP.read().await.get(addr).cloned()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn cache_test_node_channel(addr: String, channel: Channel) {
|
||||
GLOBAL_CONN_MAP.write().await.insert(addr, channel);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn test_node_channel_is_cached(addr: &str) -> bool {
|
||||
GLOBAL_CONN_MAP.read().await.contains_key(addr)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn ensure_test_rpc_secret() {
|
||||
let _ = rustfs_credentials::GLOBAL_RUSTFS_RPC_SECRET.set(TEST_RPC_SECRET.to_owned());
|
||||
}
|
||||
|
||||
pub(crate) fn storage_class_parity(storage_class: Option<&str>) -> Option<usize> {
|
||||
get_global_storage_class().and_then(|sc| sc.get_parity_for_sc(storage_class.unwrap_or_default()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user