tests: parent_ports tells an ephemeral port from the window by several

On Linux the port windows lie within net.ipv4.ip_local_port_range, as
the kernel honours no other, so the ephemeral port of a request the
range does not apply to falls into the 50-port window now and then
(CI saw 34001 in 33968-34017). The case now makes five such requests
and wants one of them outside the window: bound to it, all would be in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-18 12:58:43 +03:00
parent ef4969da19
commit 07bedfa64c

View File

@ -107,10 +107,16 @@ def run(t):
"peer.port")
t.in_range(port, MLOW, MHIGH, "CONNECT uses the range its rule sets")
# a plain GET matches the later rule, which sets no range
port = int_field(t.http(origin + "/echo", proxy=method_proxy), "peer.port")
t.not_in_range(port, MLOW, MHIGH,
"a method outside that rule keeps an ephemeral port")
# a plain GET matches the later rule, which sets no range. On Linux the
# window lies within the ephemeral range, so an ephemeral port falls in
# it now and then by chance: bound to the window every port would, so
# one of a few outside it tells them apart.
ports = [int_field(t.http(origin + "/echo", proxy=method_proxy), "peer.port")
for _ in range(5)]
outside = [p for p in ports if isinstance(p, int) and not MLOW <= p <= MHIGH]
t.ok(f"a method outside that rule keeps an ephemeral port ({ports})") if outside else \
t.fail("a method outside that rule keeps an ephemeral port",
f"some outside {MLOW}-{MHIGH}", ports)
# --- a range the platform cannot honour --------------------------------
# Linux ignores a range outside net.ipv4.ip_local_port_range, and any