Porte delle prove fuori dall'intervallo effimero (#52)
verifica / controlli (push) Successful in 29s
verifica / prove (push) Successful in 15m0s
verifica / installatore (push) Successful in 4m36s
verifica / immagine (push) Successful in 14m52s

Nella CI 350 Chromium non è partito: la porta di debug, presa dalla porta 0
del sistema e chiusa prima dell'avvio, era nell'intervallo effimero di Linux
e un'altra prova parallela l'aveva occupata nel frattempo. FreePort dà ora
porte fra 20000 e 29999, una volta sola per processo e provate prima di
darle; anche DesktopCompositionTests usa lo stesso aiuto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-16 15:12:08 +01:00
1 parent 129ca22449
commit c4c035d61f
3 files changed
+36 -13

No files matched your search

@@ -49,13 +49,42 @@ public sealed class LocalTestSite : IDisposable
public string CdnUrl(string path) => $"http://{CdnHost}{path}";
// Ports handed out by FreePort come from 20000-29999: below the ephemeral ranges of Linux (32768-60999) and Windows
// (49152-65535), so an outgoing connection of another test cannot take one between the probe and the moment the
// test binds it (a port handed out by the system's port 0 could, CI run 350 of #52). Each port is handed out once
// per process; the start depends on the process id, so two test processes on one machine rarely meet.
private const int FirstTestPort = 20000;
private const int TestPorts = 10000;
private static int _nextPort = Environment.ProcessId * 7919 % TestPorts;
/// <summary>
/// A port of 127.0.0.1 that is free now, never handed out before in this process and outside the system's ephemeral
/// range. The caller binds it soon after; nothing can reserve it in between, but no other test of this process gets
/// it and no outgoing connection is given it.
/// </summary>
public static int FreePort()
{
var probe = new TcpListener(IPAddress.Loopback, 0);
probe.Start();
var port = ((IPEndPoint)probe.LocalEndpoint).Port;
probe.Stop();
return port;
for (var attempt = 0; attempt < TestPorts; attempt++)
{
var port = FirstTestPort + (int)((uint)Interlocked.Increment(ref _nextPort) % TestPorts);
var probe = new TcpListener(IPAddress.Loopback, port);
try
{
probe.Start();
}
catch (SocketException)
{
continue;
}
finally
{
probe.Stop();
}
return port;
}
throw new InvalidOperationException("Nessuna porta libera fra 20000 e 29999.");
}
private int _disposed;
@@ -336,12 +336,5 @@ public sealed class DesktopCompositionTests
StringAssert.Contains(log, "Windows non ha legato Edge a Febe");
}
private static int FreePort()
{
var listener = new System.Net.Sockets.TcpListener(IPAddress.Loopback, 0);
listener.Start();
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();
return port;
}
private static int FreePort() => Febe.Tests.Browser.TestSupport.LocalTestSite.FreePort();
}