p2p: fix flaky test TestServerPortMapping

The test specifies `ListenAddr: ":0"`, which means a random ephemeral
port will be chosen for the TCP listener by the OS. Additionally, since
no `DiscAddr` was specified, the same port that is chosen automatically
by the OS will also be used for the UDP listener in the discovery UDP
setup. This sometimes leads to test failures if the TCP listener picks a
free TCP port that is already taken for UDP. By specifying `DiscAddr:
":0"`, the UDP port will be chosen independently from the TCP port,
fixing the random failure.

See issue #29830.
This commit is contained in:
Marius Guggenmos 2024-07-30 09:48:23 +02:00
parent b0f66e34ca
commit b4e13404a3

View file

@ -36,6 +36,7 @@ func TestServerPortMapping(t *testing.T) {
PrivateKey: newkey(),
NoDial: true,
ListenAddr: ":0",
DiscAddr: ":0",
NAT: mockNAT,
Logger: testlog.Logger(t, log.LvlTrace),
clock: clock,