test(connlib): ensure we have gaps in port ranges (#8862)

This should fix the flaky proptest.
This commit is contained in:
Thomas Eizinger
2025-04-20 21:02:55 +10:00
committed by GitHub
parent 1af7f4f8c1
commit 92534ae4ec

View File

@@ -1464,24 +1464,34 @@ mod proptests {
filters()
.prop_filter("empty filters accepts every packet", |f| !f.is_empty())
.prop_flat_map(|f| {
let filters = f.clone();
any::<ProtocolKind>()
.prop_filter_map(
"If ICMP is contained there is no way to generate gaps",
.prop_filter_map("If ICMP is contained there is no way to generate gaps", {
let f = f.clone();
move |p| {
(p != ProtocolKind::Icmp || !filters.contains(&Filter::Icmp))
.then_some(p)
},
)
(p != ProtocolKind::Icmp || !f.contains(&Filter::Icmp)).then_some(p)
}
})
.prop_filter("no gaps in port ranges", {
let f = f.clone();
move |p| !gaps(f.clone(), *p).is_empty()
})
.prop_flat_map(move |p| {
if p == ProtocolKind::Icmp {
Just((f.clone(), Protocol::Icmp)).boxed()
} else {
let f = f.clone();
select(gaps(f.clone(), p))
.prop_flat_map(move |g| {
.prop_flat_map({
let f = f.clone();
g.prop_map(move |dport| (f.clone(), p.into_protocol(dport)))
move |g| {
g.prop_map({
let f = f.clone();
move |dport| (f.clone(), p.into_protocol(dport))
})
}
})
.boxed()
}