0.5.1-pre.006
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: ks-onchain-transport/src/http_pool.rs
|
||||
// version: 9
|
||||
// version: 10
|
||||
|
||||
//! HTTP endpoint pool and role-based routing.
|
||||
|
||||
@@ -11,10 +11,21 @@ pub struct HttpEndpointPool {
|
||||
}
|
||||
|
||||
impl crate::HttpEndpointPool {
|
||||
/// Builds a pool from the active profile HTTP endpoint list.
|
||||
/// Builds a pool from an independently selected transport profile.
|
||||
pub fn from_transport_profile(
|
||||
profile: &ks_config::TransportProfileConfig,
|
||||
) -> ks_core::Result<Self> {
|
||||
return crate::HttpEndpointPool::from_http_endpoints(&profile.http_endpoints);
|
||||
}
|
||||
|
||||
/// Builds a pool from the resolved application profile HTTP endpoint list.
|
||||
pub fn from_profile(profile: &ks_config::ProfileConfig) -> ks_core::Result<Self> {
|
||||
return crate::HttpEndpointPool::from_http_endpoints(&profile.solana.http_endpoints);
|
||||
}
|
||||
|
||||
fn from_http_endpoints(endpoints: &[ks_config::HttpEndpointConfig]) -> ks_core::Result<Self> {
|
||||
let mut clients = std::vec::Vec::new();
|
||||
for endpoint in &profile.solana.http_endpoints {
|
||||
for endpoint in endpoints {
|
||||
if !endpoint.enabled {
|
||||
continue;
|
||||
}
|
||||
@@ -184,6 +195,26 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transport_profile_builds_http_pool_without_resolved_app_profile() {
|
||||
let profile = ks_config::TransportProfileConfig {
|
||||
name: "direct".to_string(),
|
||||
http_endpoints: std::vec![endpoint(
|
||||
"direct",
|
||||
"http_queries",
|
||||
std::vec!["get_version".to_string()],
|
||||
)],
|
||||
ws_endpoints: std::vec::Vec::new(),
|
||||
};
|
||||
let pool = match crate::HttpEndpointPool::from_transport_profile(&profile) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
panic!("transport profile pool creation failed: {error}")
|
||||
},
|
||||
};
|
||||
assert_eq!(pool.snapshot().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_rejects_empty_pool() {
|
||||
let result = crate::HttpEndpointPool::new(std::vec::Vec::new());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// file: ks-onchain-transport/src/ws_pool.rs
|
||||
// version: 7
|
||||
// version: 8
|
||||
|
||||
//! WebSocket endpoint pool and role-based routing.
|
||||
|
||||
@@ -11,10 +11,21 @@ pub struct WsEndpointPool {
|
||||
}
|
||||
|
||||
impl crate::WsEndpointPool {
|
||||
/// Builds a pool from the active profile WebSocket endpoint list.
|
||||
/// Builds a pool from an independently selected transport profile.
|
||||
pub fn from_transport_profile(
|
||||
profile: &ks_config::TransportProfileConfig,
|
||||
) -> ks_core::Result<Self> {
|
||||
return crate::WsEndpointPool::from_ws_endpoints(&profile.ws_endpoints);
|
||||
}
|
||||
|
||||
/// Builds a pool from the resolved application profile WebSocket endpoint list.
|
||||
pub fn from_profile(profile: &ks_config::ProfileConfig) -> ks_core::Result<Self> {
|
||||
return crate::WsEndpointPool::from_ws_endpoints(&profile.solana.ws_endpoints);
|
||||
}
|
||||
|
||||
fn from_ws_endpoints(endpoints: &[ks_config::WsEndpointConfig]) -> ks_core::Result<Self> {
|
||||
let mut clients = std::vec::Vec::new();
|
||||
for endpoint in &profile.solana.ws_endpoints {
|
||||
for endpoint in endpoints {
|
||||
if !endpoint.enabled {
|
||||
continue;
|
||||
}
|
||||
@@ -164,6 +175,26 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transport_profile_builds_ws_pool_without_resolved_app_profile() {
|
||||
let profile = ks_config::TransportProfileConfig {
|
||||
name: "direct".to_string(),
|
||||
http_endpoints: std::vec::Vec::new(),
|
||||
ws_endpoints: std::vec![endpoint(
|
||||
"direct",
|
||||
"slot_notifications",
|
||||
std::vec!["slot_subscribe".to_string()],
|
||||
)],
|
||||
};
|
||||
let pool = match crate::WsEndpointPool::from_transport_profile(&profile) {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => {
|
||||
panic!("transport profile pool creation failed: {error}")
|
||||
},
|
||||
};
|
||||
assert_eq!(pool.snapshot().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_rejects_empty_pool() {
|
||||
let result = crate::WsEndpointPool::new(std::vec::Vec::new());
|
||||
|
||||
Reference in New Issue
Block a user