From 61786830a35f666719f2a20c473f4f108213bfa8 Mon Sep 17 00:00:00 2001 From: Robert Escriva Date: Wed, 27 Nov 2024 10:44:04 -0800 Subject: [PATCH] Make delayed workloads look better --- rust/load/examples/workload-json.rs | 8 ++++---- rust/load/src/lib.rs | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/rust/load/examples/workload-json.rs b/rust/load/examples/workload-json.rs index b41930727a6e..d350bddadb6e 100644 --- a/rust/load/examples/workload-json.rs +++ b/rust/load/examples/workload-json.rs @@ -22,10 +22,10 @@ fn main() { ), ( 1.0, - Workload::Delay( - chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(), - Box::new(Workload::Nop), - ), + Workload::Delay { + after: chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(), + wrap: Box::new(Workload::Nop), + }, ), ]); println!("{}", serde_json::to_string_pretty(&w).unwrap()); diff --git a/rust/load/src/lib.rs b/rust/load/src/lib.rs index 53c24d0e6915..7d077d1aca70 100644 --- a/rust/load/src/lib.rs +++ b/rust/load/src/lib.rs @@ -202,7 +202,10 @@ pub enum Workload { #[serde(rename = "hybrid")] Hybrid(Vec<(f64, Workload)>), #[serde(rename = "delay")] - Delay(chrono::DateTime, Box), + Delay { + after: chrono::DateTime, + wrap: Box, + }, } impl Workload { @@ -227,7 +230,7 @@ impl Workload { workload.resolve_by_name(workloads)?; } } - Workload::Delay(_, w) => w.resolve_by_name(workloads)?, + Workload::Delay { after: _, wrap } => wrap.resolve_by_name(workloads)?, } Ok(()) } @@ -285,7 +288,7 @@ impl Workload { "miscalculation of total hybrid probabilities".to_string(), ))) } - Workload::Delay(_, w) => Box::pin(w.step(client, data_set, guac)).await, + Workload::Delay { after: _, wrap } => Box::pin(wrap.step(client, data_set, guac)).await, } } @@ -296,7 +299,7 @@ impl Workload { Workload::Get(_) => true, Workload::Query(_) => true, Workload::Hybrid(hybrid) => hybrid.iter().any(|(_, w)| w.is_active()), - Workload::Delay(after, w) => chrono::Utc::now() >= *after && w.is_active(), + Workload::Delay { after, wrap } => chrono::Utc::now() >= *after && wrap.is_active(), } } } @@ -788,10 +791,10 @@ mod tests { [ 1.0, { - "delay": [ - "2021-01-01T00:00:00Z", - "nop" - ] + "delay": { + "after": "2021-01-01T00:00:00Z", + "wrap": "nop" + } } ] ] @@ -817,10 +820,11 @@ mod tests { ), ( 1.0, - Workload::Delay( - chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00").unwrap(), - Box::new(Workload::Nop), - ), + Workload::Delay { + after: chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00+00:00") + .unwrap(), + wrap: Box::new(Workload::Nop), + }, ), ]); assert_eq!(json, serde_json::to_string_pretty(&workload).unwrap());