From b47530d66a7b40219f37b8f2ea7effefd48b36c7 Mon Sep 17 00:00:00 2001 From: manuelgdlvh Date: Wed, 14 May 2025 21:22:09 +0200 Subject: [PATCH] feat: Add tests for max path conflicts modification --- actix-router/src/router.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/actix-router/src/router.rs b/actix-router/src/router.rs index f84b5e277..1e1b2154d 100644 --- a/actix-router/src/router.rs +++ b/actix-router/src/router.rs @@ -314,4 +314,38 @@ mod tests { assert_eq!(*h, 11); assert_eq!(&path["val"], "ttt"); } + + #[test] + fn test_max_path_conflicts() { + let mut router = Router::::build(); + router.path("/test", 10).0.set_id(0); + router.path("/test/{val}", 11).0.set_id(1); + let router = router.finish(); + + assert_eq!(1, router.max_path_conflicts); + + let mut router = Router::::build(); + router.path("/test", 10).0.set_id(0); + router.path("/test", 11).0.set_id(1); + router.path("/test2", 11).0.set_id(1); + router.path("/test2", 11).0.set_id(1); + router.path("/test2", 11).0.set_id(1); + + let router = router.finish(); + + assert_eq!(3, router.max_path_conflicts); + + let failures_until_fn_builder = |mut num_failures: u16| { + move |_: &Path<&str>, _: &()| { + if num_failures == 0 { + return true; + } + num_failures -= 1; + false + } + }; + + assert!(router.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(3)).is_none()); + assert!(router.recognize_fn(&mut Path::new("/test2"), failures_until_fn_builder(2)).is_some()); + } }