Ensure response barrier is always dropped, even if request is canceled

This commit is contained in:
Antonio Scandurra 2022-02-12 10:23:50 +01:00
parent 174c9d7ab0
commit 5a7d391d73
2 changed files with 125 additions and 6 deletions

View file

@ -550,8 +550,11 @@ impl Background {
pub async fn simulate_random_delay(&self) {
match self {
Self::Deterministic { executor, .. } => {
if executor.state.lock().rng.gen_range(0..100) < 20 {
yield_now().await;
if executor.state.lock().rng.gen_bool(0.2) {
let yields = executor.state.lock().rng.gen_range(1..=10);
for _ in 0..yields {
yield_now().await;
}
}
}
_ => panic!("this method can only be called on a deterministic executor"),