feat(infra): auto-commit con 4 cambios
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -15,7 +16,16 @@ import (
|
||||
func newUnixDockerServer(t *testing.T, handler http.Handler) (socketPath string) {
|
||||
t.Helper()
|
||||
|
||||
socketPath = t.TempDir() + "/docker_exec_test.sock"
|
||||
// Los sockets Unix tienen un limite de ~108 bytes en sun_path (Linux).
|
||||
// t.TempDir() incluye el nombre del subtest (largo) y un TMPDIR que puede
|
||||
// ser largo, excediendo el limite -> "bind: invalid argument". Crear un
|
||||
// directorio corto directamente bajo /tmp.
|
||||
dir, err := os.MkdirTemp("/tmp", "dk")
|
||||
if err != nil {
|
||||
t.Fatalf("mkdtemp: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(dir) })
|
||||
socketPath = dir + "/d.sock"
|
||||
ln, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
t.Fatalf("listen unix %s: %v", socketPath, err)
|
||||
|
||||
@@ -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