in nfm-controller/src/events/sock_cache.rs [499:561]
fn test_get_sock_deltas_all_changed() {
let mut sock_cache = SockCache::new();
let mut sock_stream: HashMap<SockKey, AggSockStats> = HashMap::new();
// Create a slew of sockets in the incoming stream.
let sock_keys: Vec<u64> = vec![99, 101, 4, 55, 19, 79];
for sock_key in sock_keys.iter() {
sock_stream.insert(
*sock_key,
AggSockStats {
cpus: vec![*sock_key as u32 % 2, 100],
stats: SockStats {
bytes_delivered: sock_key * 4,
..Default::default()
},
},
);
}
// Create sock stats already in cache, but with smaller values.
let mut old_stream: HashMap<SockKey, AggSockStats> = HashMap::new();
for (sock_key, _val_after) in sock_stream.iter() {
let val_before = AggSockStats {
cpus: vec![],
stats: SockStats {
bytes_delivered: *sock_key,
..Default::default()
},
};
old_stream.insert(*sock_key, val_before);
}
let result = sock_cache.update_stats_and_get_deltas(&mut old_stream, STALENESS_TS);
assert_eq!(
result,
SockOperationResult {
completed: 0,
partial: sock_keys.len().try_into().unwrap(),
failed: 0,
}
);
// Validate the resultant deltas placed into the sock stream.
let result = sock_cache.update_stats_and_get_deltas(&mut sock_stream, STALENESS_TS);
assert_eq!(
result,
SockOperationResult {
completed: sock_keys.len().try_into().unwrap(),
partial: 0,
failed: 0,
}
);
assert_eq!(sock_stream.len(), sock_keys.len());
for (sock_key, actual_delta) in sock_stream.iter() {
let expected_delta = AggSockStats {
stats: SockStats {
bytes_delivered: sock_key * 3,
..Default::default()
},
cpus: vec![*sock_key as u32 % 2, 100],
};
assert_eq!(*actual_delta, expected_delta);
}
}