patches errors from clippy::unchecked_duration_subtraction

https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction
This commit is contained in:
behzad nouri 2022-12-06 09:20:47 -05:00
parent 401f66c830
commit 9433c06745
3 changed files with 31 additions and 13 deletions

View File

@ -6752,8 +6752,11 @@ pub(crate) mod tests {
"retry_iteration=0, elapsed < 2^0 * RETRANSMIT_BASE_DELAY_MS"
);
progress.get_retransmit_info_mut(0).unwrap().retry_time =
Some(Instant::now() - Duration::from_millis(RETRANSMIT_BASE_DELAY_MS + 1));
progress.get_retransmit_info_mut(0).unwrap().retry_time = Some(
Instant::now()
.checked_sub(Duration::from_millis(RETRANSMIT_BASE_DELAY_MS + 1))
.unwrap(),
);
ReplayStage::retransmit_latest_unpropagated_leader_slot(
&poh_recorder,
&retransmit_slots_sender,
@ -6781,8 +6784,11 @@ pub(crate) mod tests {
"retry_iteration=1, elapsed < 2^1 * RETRY_BASE_DELAY_MS"
);
progress.get_retransmit_info_mut(0).unwrap().retry_time =
Some(Instant::now() - Duration::from_millis(RETRANSMIT_BASE_DELAY_MS + 1));
progress.get_retransmit_info_mut(0).unwrap().retry_time = Some(
Instant::now()
.checked_sub(Duration::from_millis(RETRANSMIT_BASE_DELAY_MS + 1))
.unwrap(),
);
ReplayStage::retransmit_latest_unpropagated_leader_slot(
&poh_recorder,
&retransmit_slots_sender,
@ -6794,8 +6800,11 @@ pub(crate) mod tests {
"retry_iteration=1, elapsed < 2^1 * RETRANSMIT_BASE_DELAY_MS"
);
progress.get_retransmit_info_mut(0).unwrap().retry_time =
Some(Instant::now() - Duration::from_millis(2 * RETRANSMIT_BASE_DELAY_MS + 1));
progress.get_retransmit_info_mut(0).unwrap().retry_time = Some(
Instant::now()
.checked_sub(Duration::from_millis(2 * RETRANSMIT_BASE_DELAY_MS + 1))
.unwrap(),
);
ReplayStage::retransmit_latest_unpropagated_leader_slot(
&poh_recorder,
&retransmit_slots_sender,
@ -6818,8 +6827,11 @@ pub(crate) mod tests {
.unwrap()
.increment_retry_iteration();
progress.get_retransmit_info_mut(0).unwrap().retry_time =
Some(Instant::now() - Duration::from_millis(2 * RETRANSMIT_BASE_DELAY_MS + 1));
progress.get_retransmit_info_mut(0).unwrap().retry_time = Some(
Instant::now()
.checked_sub(Duration::from_millis(2 * RETRANSMIT_BASE_DELAY_MS + 1))
.unwrap(),
);
ReplayStage::retransmit_latest_unpropagated_leader_slot(
&poh_recorder,
&retransmit_slots_sender,
@ -6831,8 +6843,11 @@ pub(crate) mod tests {
"retry_iteration=3, elapsed < 2^3 * RETRANSMIT_BASE_DELAY_MS"
);
progress.get_retransmit_info_mut(0).unwrap().retry_time =
Some(Instant::now() - Duration::from_millis(8 * RETRANSMIT_BASE_DELAY_MS + 1));
progress.get_retransmit_info_mut(0).unwrap().retry_time = Some(
Instant::now()
.checked_sub(Duration::from_millis(8 * RETRANSMIT_BASE_DELAY_MS + 1))
.unwrap(),
);
ReplayStage::retransmit_latest_unpropagated_leader_slot(
&poh_recorder,
&retransmit_slots_sender,

View File

@ -104,7 +104,9 @@ impl TransactionGenerator {
fn new(transaction_params: TransactionParams) -> Self {
TransactionGenerator {
blockhash: Hash::default(),
last_generated: (Instant::now() - Duration::from_secs(100)), //to force generation when generate is called
last_generated: Instant::now()
.checked_sub(Duration::from_secs(100))
.unwrap(), //to force generation when generate is called
transaction_params,
}
}

View File

@ -15657,8 +15657,9 @@ pub mod tests {
assert_eq!(recycle_stores.total_bytes(), store_file_size * 2);
// expiration for only too old entries
recycle_stores.entries[0].0 =
Instant::now() - Duration::from_secs(EXPIRATION_TTL_SECONDS + 1);
recycle_stores.entries[0].0 = Instant::now()
.checked_sub(Duration::from_secs(EXPIRATION_TTL_SECONDS + 1))
.unwrap();
let expired = recycle_stores.expire_old_entries();
assert_eq!(
expired