Skip to content

Fix flaky refused-port socket tests - #1891

Draft
Weidong Cui (wdcui) wants to merge 6 commits into
uliteboxfrom
wdcui/ulitebox/reserve-refused-ports
Draft

Weidong Cui (wdcui) wants to merge 6 commits into
uliteboxfrom
wdcui/ulitebox/reserve-refused-ports

Conversation

@wdcui

@wdcui Weidong Cui (wdcui) commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

This PR fixes flaky socket tests, such as AArch64's tcp_broker.c:333 failure, and removes duplicated ones. Tests picked a port to be refused by binding an ephemeral port and freeing it before use, so a test running in parallel could take it. A shared test-support helper now holds each refused port for the whole test: a bound, non-listening TCP socket; on Linux, a UDP socket connected to itself; on Windows, a UDP port outside the dynamic range. The broker's UDP refusal tests move into udp_broker.c, which runs on Linux and Windows.

Weidong Cui (wdcui) and others added 3 commits November 13, 2026 19:44
The TCP broker tests picked a port to be refused by binding an
ephemeral port and freeing it before the guest connected, so a test
running in parallel could take the port and the guest's connection was
not refused. Keep a socket bound to the port, without listening, for
the whole test: connections to it are refused, and no other socket can
take it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
The Windows runner's TCP broker tests and two broker socket tests also
freed a port before expecting connections to it to be refused, so a
test running in parallel could take the port. As the Linux runner's
tests now do, keep a socket bound to the port, without listening, for
the whole test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Several UDP tests freed a port shortly before sending to it and
expecting the datagram to be refused, so a test running in parallel
could take the port and receive the datagram. On Linux, keep a socket
bound to the port, connected to itself, for the whole test: Linux
refuses datagrams from other sockets, as for a closed port. Winsock
discards them instead, so on Windows, leave the port unbound below the
dynamic port range, reserved by a TCP listener on the same port, as the
broker's UDP tests already did.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
@wdcui Weidong Cui (wdcui) changed the title Hold refused ports for the TCP broker tests Hold refused ports in the socket tests Nov 14, 2026
Weidong Cui (wdcui) and others added 3 commits November 14, 2026 09:51
tcp_broker.c and the broker's loopback TCP test each checked that a
connect to a refused port fails with ECONNREFUSED and reports POLLERR
until the error is taken. tcp_broker_states.c checks the same, more
strictly, end to end on Linux and Windows, so drop both copies, along
with tcp_broker's refused-port argument. Rebuild the Windows runner's
tcp_broker binary for the new arguments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
Broker unit tests checked how a connected UDP socket reports the ICMP
errors its datagrams cause: a send takes a pending error, a send or
connect that fails for another reason leaves it, and a socket shut down
for reading still reports each error. Check these in udp_broker.c
instead, where they hold on Linux and run on both broker hosts, and
drop the unit tests. Keep the unit check of a failed send while the
error is still with the transport, which a guest cannot arrange.
Rebuild the Windows runner's udp_broker binary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
The helpers that hold a loopback port that refuses TCP connections or UDP
datagrams were written three times: in the broker's socket tests and in
both runners' tests, with the Windows UDP reservation twice. Move them to
a test_support module behind a new test-support feature of
litebox_broker_userland, which its tests and both runners' tests use. The
Linux runner no longer needs socket2 for them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5406de6-bab4-4f3b-b232-ae238032c2c2
@wdcui Weidong Cui (wdcui) changed the title Hold refused ports in the socket tests Fix flaky socket tests and UDP error ordering Nov 14, 2026
@wdcui
Weidong Cui (wdcui) force-pushed the wdcui/ulitebox/reserve-refused-ports branch from 8528b57 to b6c57c7 Compare November 15, 2026 20:26
@wdcui Weidong Cui (wdcui) changed the title Fix flaky socket tests and UDP error ordering Fix flaky refused-port socket tests Nov 15, 2026
@github-actions

Copy link
Copy Markdown

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant