MCPcopy Create free account
hub / github.com/ermak-dev/cloudpub / ping_test

Function ping_test

client/src/ping.rs:81–116  ·  view source on GitHub ↗
(endpoint: ServerEndpoint, bare: bool)

Source from the content-addressed store, hash-verified

79}
80
81pub async fn ping_test(endpoint: ServerEndpoint, bare: bool) -> Result<String> {
82 debug!("Running ping test on {}", endpoint);
83 let addr = format!("{}:{}", endpoint.remote_addr, endpoint.remote_port);
84
85 let _stop_tx = start(endpoint.client.as_ref().unwrap().local_port as u16)
86 .await
87 .context("Failed to start ping service")?;
88
89 // Wait for the server to start
90 sleep(Duration::from_millis(100)).await;
91
92 let settings = Settings {
93 warm_up_count: 1,
94 msg_count: 10,
95 msg_size: 48,
96 sleep_time: 0,
97 };
98
99 let client = TcpStream::connect(&addr)
100 .await
101 .context(format!("Failed to connect to {}", addr))?;
102 let mut times = ping_tcp(client, &settings).await;
103
104 if times.is_empty() {
105 return Ok(crate::t!("error-measurement"));
106 }
107
108 times.sort();
109
110 if bare {
111 let p50 = times.len() as f64 * 0.5;
112 Ok(format!("{}", times[p50 as usize] / 1_000))
113 } else {
114 Ok(format_stats(times))
115 }
116}
117
118// TCP implementation
119async fn ping_tcp(mut client: TcpStream, settings: &Settings) -> Vec<u32> {

Callers 2

main_loopFunction · 0.85
pingMethod · 0.85

Calls 5

startFunction · 0.85
ping_tcpFunction · 0.85
format_statsFunction · 0.85
is_emptyMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected