MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / test_update_buckets

Function test_update_buckets

rate_limiter/src/lib.rs:877–909  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

875
876 #[test]
877 fn test_update_buckets() {
878 let mut x = RateLimiter::new(1000, 2000, 1000, 10, 20, 1000).unwrap();
879
880 let initial_bw = x.bandwidth();
881 let initial_ops = x.ops();
882
883 x.update_buckets(BucketUpdate::None, BucketUpdate::None);
884 assert_eq!(x.bandwidth(), initial_bw);
885 assert_eq!(x.ops(), initial_ops);
886
887 let new_bw = TokenBucket::new(123, 0, 57).unwrap();
888 let new_ops = TokenBucket::new(321, 12346, 89).unwrap();
889 x.update_buckets(
890 BucketUpdate::Update(new_bw.clone()),
891 BucketUpdate::Update(new_ops.clone()),
892 );
893
894 {
895 let mut guard = x.inner.lock().unwrap();
896 // We have manually adjust the last_update field, because it changes when update_buckets()
897 // constructs new buckets (and thus gets a different value for last_update). We do this so
898 // it makes sense to test the following assertions.
899 guard.bandwidth.as_mut().unwrap().last_update = new_bw.last_update;
900 guard.ops.as_mut().unwrap().last_update = new_ops.last_update;
901 }
902
903 assert_eq!(x.bandwidth(), Some(new_bw));
904 assert_eq!(x.ops(), Some(new_ops));
905
906 x.update_buckets(BucketUpdate::Disabled, BucketUpdate::Disabled);
907 assert_eq!(x.bandwidth(), None);
908 assert_eq!(x.ops(), None);
909 }
910
911 #[test]
912 fn test_rate_limiter_debug() {

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
update_bucketsMethod · 0.80
bandwidthMethod · 0.45
opsMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected