From 6b63160bc4ab75a6766fbaf8ecc1052fef36120e Mon Sep 17 00:00:00 2001 From: Brett Mcchesney Date: Thu, 18 May 2023 09:13:10 -0600 Subject: [PATCH 1/2] Filter out equal IpAddrs for regex matching Applying a "hold all" panics as the resolution does not take into account matching Ips. --- src/lib.rs | 5 ++++- src/sim.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fc8c2f7..852793e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,10 @@ const TRACING_TARGET: &str = "turmoil"; pub(crate) fn for_pairs(a: &Vec, b: &Vec, mut f: impl FnMut(IpAddr, IpAddr)) { for first in a { for second in b { - f(*first, *second) + // skip for the host + if first != second { + f(*first, *second) + } } } } diff --git a/src/sim.rs b/src/sim.rs index e6b694d..ca7ca7f 100644 --- a/src/sim.rs +++ b/src/sim.rs @@ -687,4 +687,37 @@ mod test { Ok(()) } + + #[test] + #[cfg(feature = "regex")] + fn hold_all() -> Result { + let mut sim = Builder::new().build(); + + sim.host("host", || async { + let l = TcpListener::bind("0.0.0.0:1234").await?; + + loop { + _ = l.accept().await?; + } + }); + + sim.client("test", async { + hold(regex::Regex::new(r".*")?, regex::Regex::new(r".*")?); + + assert!(tokio::time::timeout( + Duration::from_millis(100), + TcpStream::connect("host:1234") + ) + .await + .is_err()); + + crate::release(regex::Regex::new(r".*")?, regex::Regex::new(r".*")?); + + assert!(TcpStream::connect("host:1234").await.is_ok()); + + Ok(()) + }); + + sim.run() + } } From 5d7cc0c80ce99b0d1d677ccf1431ac4573b7b987 Mon Sep 17 00:00:00 2001 From: Brett McChesney <39924297+mcches@users.noreply.github.com> Date: Thu, 18 May 2023 09:16:37 -0600 Subject: [PATCH 2/2] Update lib.rs --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 852793e..e06e558 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,7 @@ const TRACING_TARGET: &str = "turmoil"; pub(crate) fn for_pairs(a: &Vec, b: &Vec, mut f: impl FnMut(IpAddr, IpAddr)) { for first in a { for second in b { - // skip for the host + // skip for the same host if first != second { f(*first, *second) }