Download this file
| 1 | package thin |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "net" |
| 7 | "os" |
| 8 | "path/filepath" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | // The coordinator's tool socket opens whatever the state directory's |
| 14 | // length: a Unix socket path holds 107 bytes, and the staging suite's |
| 15 | // state under a long TMPDIR failed most coordinator starts (2026-11-22). |
| 16 | func TestToolSocketUnderLongStateDir(t *testing.T) { |
| 17 | root := filepath.Join(t.TempDir(), strings.Repeat("s", 100)) |
| 18 | if err := os.Mkdir(root, 0700); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | for i := 0; i < 20; i++ { |
| 22 | s, err := openToolSet(context.Background(), root, converseSet(false), nil) |
| 23 | if err != nil { |
| 24 | t.Fatalf("open %d: %v", i, err) |
| 25 | } |
| 26 | info, err := os.Lstat(s.Path) |
| 27 | if err != nil || info.Mode()&os.ModeSocket == 0 || info.Mode().Perm() != 0600 || filepath.Base(s.Path) != "equipo.sock" || filepath.Dir(filepath.Dir(s.Path)) != root { |
| 28 | t.Fatalf("socket %s: %v %v", s.Path, info, err) |
| 29 | } |
| 30 | dir, err := os.Open(filepath.Dir(s.Path)) |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | conn, err := net.Dial("unix", fmt.Sprintf("/proc/self/fd/%d/equipo.sock", dir.Fd())) |
| 35 | dir.Close() |
| 36 | if err != nil { |
| 37 | t.Fatalf("dial %d: %v", i, err) |
| 38 | } |
| 39 | conn.Close() |
| 40 | s.Close() |
| 41 | } |
| 42 | } |
| 43 | |