// Copyright (C) 2026, Cloudflare, Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#[test] fn metrics_updated_with_ex_data() { // Test that ex_data fields are flattened into the same object let ex_data = ExData::from([( "delivery_rate".to_string(),
serde_json::json!(DELIVERY_RATE),
)]);
let json = serde_json::to_value(&metrics).unwrap();
// Verify standard fields are present
assert_eq!(json["min_rtt"], MIN_RTT);
assert_eq!(json["congestion_window"], CONGESTION_WINDOW);
// Verify ex_data field is flattened (not nested under "ex_data")
assert_eq!(json["delivery_rate"], DELIVERY_RATE);
assert!(json.get("ex_data").is_none(), "ex_data should be flattened");
}
#[test] fn metrics_updated_ex_data_collision() { // Test collision: same field set via struct AND ex_data. // With serde's preserve_order feature and ex_data at the top of the // struct, standard fields are serialized last and take precedence.
let ex_data = ExData::from([( "min_rtt".to_string(),
serde_json::json!(COLLISION_VALUE),
)]);
let metrics = MetricsUpdated {
min_rtt: Some(MIN_RTT), // struct field value
ex_data, // ex_data also has min_rtt
..Default::default()
};
let json = serde_json::to_value(&metrics).unwrap();
// Standard field wins in collision - ex_data cannot overwrite standard // fields, which prevents accidental data corruption.
assert_eq!(json["min_rtt"], MIN_RTT);
}
#[test] fn metrics_updated_round_trip() { // Test serialization -> deserialization round-trip let ex_data = ExData::from([( "delivery_rate".to_string(),
serde_json::json!(DELIVERY_RATE),
)]);
let original = MetricsUpdated {
min_rtt: Some(MIN_RTT),
smoothed_rtt: Some(SMOOTHED_RTT),
congestion_window: Some(CONGESTION_WINDOW),
pacing_rate: Some(PACING_RATE),
ex_data,
..Default::default()
};
let json_str = serde_json::to_string(&original).unwrap(); let deserialized: MetricsUpdated = serde_json::from_str(&json_str).unwrap();
#[test] fn metrics_updated_no_ex_data() { // Test that ex_data is not present when not used let metrics = MetricsUpdated {
min_rtt: Some(MIN_RTT),
congestion_window: Some(CONGESTION_WINDOW),
..Default::default()
};
let json = serde_json::to_value(&metrics).unwrap();
// Verify standard fields are present
assert_eq!(json["min_rtt"], MIN_RTT);
assert_eq!(json["congestion_window"], CONGESTION_WINDOW);
// Verify ex_data is not present
assert!(
json.get("ex_data").is_none(), "ex_data should not be present"
);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.