Insert random delays when sending and receiving websocket messages in tests
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
d241ab6370
commit
2b8685c1a2
6 changed files with 53 additions and 21 deletions
|
@ -5,7 +5,7 @@ use collections::HashMap;
|
|||
use parking_lot::Mutex;
|
||||
use postage::{barrier, prelude::Stream as _};
|
||||
use rand::prelude::*;
|
||||
use smol::{channel, prelude::*, Executor, Timer};
|
||||
use smol::{channel, future::yield_now, prelude::*, Executor, Timer};
|
||||
use std::{
|
||||
any::Any,
|
||||
fmt::{self, Debug, Display},
|
||||
|
@ -528,6 +528,17 @@ impl Background {
|
|||
task.await;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
_ => panic!("this method can only be called on a deterministic executor"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Scope<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue