parent
b331b9f6a3
commit
d11eb04d12
13 changed files with 163 additions and 973 deletions
|
|
@ -47,7 +47,7 @@ fn pong(tm: &TypeMap, data: impl Into<String>) -> Result<CommunicationValue, Str
|
|||
CommunicationValue::from_comm(CommunicationType::Pong, tm)
|
||||
.add_data(desc_id, DataValue::Str("MTP example response".into()))
|
||||
.map_err(|e| e.to_string())?
|
||||
.add_data(ts_id, DataValue::UnsignedNumber(now as u128))
|
||||
.add_data(ts_id, DataValue::UnsignedNumber(now))
|
||||
.map_err(|e| e.to_string())?
|
||||
.add_data(data_id, DataValue::Str(data.into()))
|
||||
.map_err(|e| e.to_string())
|
||||
|
|
@ -388,7 +388,7 @@ pub fn process_and_respond(
|
|||
let response = CommunicationValue::from_comm(CommunicationType::Pong, tm)
|
||||
.add_data(desc_id, description)
|
||||
.map_err(|e| e.to_string())?
|
||||
.add_data(ts_id, DataValue::UnsignedNumber(now as u128))
|
||||
.add_data(ts_id, DataValue::UnsignedNumber(now))
|
||||
.map_err(|e| e.to_string())?
|
||||
.add_data(
|
||||
data_id,
|
||||
|
|
|
|||
|
|
@ -100,10 +100,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
serde_json::to_string_pretty(&*db).ok()
|
||||
};
|
||||
|
||||
if let Some(json) = json {
|
||||
if let Err(error) = tokio::fs::write("clients.json", json).await {
|
||||
eprintln!("Failed to persist clients.json: {error}");
|
||||
}
|
||||
if let Some(json) = json
|
||||
&& let Err(error) = tokio::fs::write("clients.json", json).await
|
||||
{
|
||||
eprintln!("Failed to persist clients.json: {error}");
|
||||
}
|
||||
|
||||
println!("Registered new client with ID: {id}");
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ pub struct ServerMetrics {
|
|||
}
|
||||
|
||||
impl ServerMetrics {
|
||||
#[cfg(test)]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(Inner {
|
||||
|
|
@ -218,6 +219,7 @@ impl ServerMetrics {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn snapshot(&self) -> ServerMetricsFile {
|
||||
let inner = self.inner.lock().unwrap();
|
||||
self.to_file(&inner)
|
||||
|
|
@ -553,11 +555,11 @@ mod tests {
|
|||
let metrics = ServerMetrics::new();
|
||||
|
||||
for i in 0..3 {
|
||||
let mut session = metrics.start_session(1000 + i as u64, format!("session {i}"));
|
||||
let mut session = metrics.start_session(1000 + i, format!("session {i}"));
|
||||
for _ in 0..(i + 1) * 2 {
|
||||
session.record_message(Duration::from_millis(1 + i), true);
|
||||
}
|
||||
session.record_pipe((i as u64 + 1) * 1000);
|
||||
session.record_pipe((i + 1) * 1000);
|
||||
session.finish(format!("exit {i}"));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue