in glean-core/src/upload/mod.rs [985:1041]
fn limits_the_number_of_pings_when_there_is_rate_limiting() {
let (glean, dir) = new_glean(None);
let mut upload_manager = PingUploadManager::no_policy(dir.path());
// Add a rate limiter to the upload mangager with max of 10 pings every 3 seconds.
let max_pings_per_interval = 10;
upload_manager.set_rate_limiter(3, 10);
// Enqueue the max number of pings allowed per uploading window
for _ in 0..max_pings_per_interval {
upload_manager.enqueue_ping(
&glean,
PingPayload {
document_id: Uuid::new_v4().to_string(),
upload_path: PATH.into(),
json_body: "".into(),
headers: None,
body_has_info_sections: true,
ping_name: "ping-name".into(),
uploader_capabilities: vec![],
},
);
}
// Verify a request is returned for each submitted ping
for _ in 0..max_pings_per_interval {
let task = upload_manager.get_upload_task(&glean, false);
assert!(task.is_upload());
}
// Enqueue just one more ping
upload_manager.enqueue_ping(
&glean,
PingPayload {
document_id: Uuid::new_v4().to_string(),
upload_path: PATH.into(),
json_body: "".into(),
headers: None,
body_has_info_sections: true,
ping_name: "ping-name".into(),
uploader_capabilities: vec![],
},
);
// Verify that we are indeed told to wait because we are at capacity
match upload_manager.get_upload_task(&glean, false) {
PingUploadTask::Wait { time } => {
// Wait for the uploading window to reset
thread::sleep(Duration::from_millis(time));
}
_ => panic!("Expected upload manager to return a wait task!"),
};
let task = upload_manager.get_upload_task(&glean, false);
assert!(task.is_upload());
}