feat(infra): auto-commit con 4 cambios

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-03 16:44:23 +02:00
parent 6aec0413bb
commit fa09ff9866
4 changed files with 136 additions and 10 deletions
+18 -2
View File
@@ -11,8 +11,10 @@ func TestSSHTunnelOpenClose(t *testing.T) {
conn := skipIfNoSSH(t)
t.Run("abre tunel y lo cierra", func(t *testing.T) {
// Usar puerto alto aleatorio para evitar conflictos
localPort := 19876
// Puerto efimero libre: un puerto fijo daba "address already in use"
// cuando el paquete corre con -count o concurrentemente con otra
// ejecucion de `go test` del mismo paquete.
localPort := freeTCPPort(t)
// Tunel a localhost:22 del remoto (el propio sshd)
pid, err := SSHTunnelOpen(conn, localPort, "localhost", 22)
if err != nil {
@@ -47,3 +49,17 @@ func TestSSHTunnelOpenClose(t *testing.T) {
}
})
}
// freeTCPPort asks the kernel for a free TCP port on loopback by binding to
// port 0, reading the assigned port, and releasing it. A small race window
// exists before the caller reuses the port, but it avoids the hard collisions
// of a fixed port across concurrent or repeated test runs.
func freeTCPPort(t *testing.T) int {
t.Helper()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("freeTCPPort: %v", err)
}
defer l.Close()
return l.Addr().(*net.TCPAddr).Port
}