feat(infra): auto-commit con 4 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user