test(resilience): use short control socket path in relay tests
macOS t.TempDir paths exceed the 104-byte AF_UNIX limit, so the relay could not bind its control socket on the macOS runner.
- commit
- 0a8685a671dfe27ba7b69505d4e3d9809f718a52
- author
- brice · · 2026-10-07 06:43 UTC
- parent
- 4c975c7
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +13 -6
M scripts/remote-resilience-harness/relay/main_test.go +13 -6
| @@ -41,12 +41,21 @@ func TestTCPRelayPreservesBytesAndStops(t *testing.T) { | |||
| 41 | 41 | require.Equal(t, uint64(len(payload)), r.bytes.Load()) | |
| 42 | 42 | } | |
| 43 | 43 | ||
| 44 | + | // controlSocketPath returns a socket path in a short private directory: the | |
| 45 | + | // macOS t.TempDir path exceeds the 104-byte AF_UNIX limit. | |
| 46 | + | func controlSocketPath(t *testing.T) string { | |
| 47 | + | t.Helper() | |
| 48 | + | directory, err := os.MkdirTemp("/tmp", "relay") | |
| 49 | + | require.NoError(t, err) | |
| 50 | + | t.Cleanup(func() { _ = os.RemoveAll(directory) }) | |
| 51 | + | require.NoError(t, os.Chmod(directory, 0700)) | |
| 52 | + | return filepath.Join(directory, "control.sock") | |
| 53 | + | } | |
| 54 | + | ||
| 44 | 55 | func TestRelayShutdownClosesListeners(t *testing.T) { | |
| 45 | 56 | ctx, cancel := context.WithCancel(t.Context()) | |
| 46 | 57 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | |
| 47 | - | directory := t.TempDir() | |
| 48 | - | require.NoError(t, os.Chmod(directory, 0700)) | |
| 49 | - | path := filepath.Join(directory, "control.sock") | |
| 58 | + | path := controlSocketPath(t) | |
| 50 | 59 | done := make(chan error, 1) | |
| 51 | 60 | go func() { done <- r.serve("127.0.0.1:0", path) }() | |
| 52 | 61 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | |
| @@ -115,9 +124,7 @@ func TestRelayControlRoundTrip(t *testing.T) { | |||
| 115 | 124 | ctx, cancel := context.WithCancel(t.Context()) | |
| 116 | 125 | defer cancel() | |
| 117 | 126 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | |
| 118 | - | directory := t.TempDir() | |
| 119 | - | require.NoError(t, os.Chmod(directory, 0700)) | |
| 120 | - | path := filepath.Join(directory, "control.sock") | |
| 127 | + | path := controlSocketPath(t) | |
| 121 | 128 | done := make(chan error, 1) | |
| 122 | 129 | go func() { done <- r.serve("127.0.0.1:0", path) }() | |
| 123 | 130 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | |
| @@ -41,12 +41,21 @@ func TestTCPRelayPreservesBytesAndStops(t *testing.T) { | |||||
| 41 | require.Equal(t, uint64(len(payload)), r.bytes.Load()) | 41 | require.Equal(t, uint64(len(payload)), r.bytes.Load()) | ||
| 42 | } | 42 | } | ||
| 43 | 43 | ||||
| 44 | + | // controlSocketPath returns a socket path in a short private directory: the | |||
| 45 | + | // macOS t.TempDir path exceeds the 104-byte AF_UNIX limit. | |||
| 46 | + | func controlSocketPath(t *testing.T) string { | |||
| 47 | + | t.Helper() | |||
| 48 | + | directory, err := os.MkdirTemp("/tmp", "relay") | |||
| 49 | + | require.NoError(t, err) | |||
| 50 | + | t.Cleanup(func() { _ = os.RemoveAll(directory) }) | |||
| 51 | + | require.NoError(t, os.Chmod(directory, 0700)) | |||
| 52 | + | return filepath.Join(directory, "control.sock") | |||
| 53 | + | } | |||
| 54 | + | ||||
| 44 | func TestRelayShutdownClosesListeners(t *testing.T) { | 55 | func TestRelayShutdownClosesListeners(t *testing.T) { | ||
| 45 | ctx, cancel := context.WithCancel(t.Context()) | 56 | ctx, cancel := context.WithCancel(t.Context()) | ||
| 46 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | 57 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | ||
| 47 | - | directory := t.TempDir() | 58 | + | path := controlSocketPath(t) |
| 48 | - | require.NoError(t, os.Chmod(directory, 0700)) | |||
| 49 | - | path := filepath.Join(directory, "control.sock") | |||
| 50 | done := make(chan error, 1) | 59 | done := make(chan error, 1) | ||
| 51 | go func() { done <- r.serve("127.0.0.1:0", path) }() | 60 | go func() { done <- r.serve("127.0.0.1:0", path) }() | ||
| 52 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | 61 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | ||
| @@ -115,9 +124,7 @@ func TestRelayControlRoundTrip(t *testing.T) { | |||||
| 115 | ctx, cancel := context.WithCancel(t.Context()) | 124 | ctx, cancel := context.WithCancel(t.Context()) | ||
| 116 | defer cancel() | 125 | defer cancel() | ||
| 117 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | 126 | r := &relay{ctx: ctx, cancel: cancel, connections: make(map[net.Conn]struct{})} | ||
| 118 | - | directory := t.TempDir() | 127 | + | path := controlSocketPath(t) |
| 119 | - | require.NoError(t, os.Chmod(directory, 0700)) | |||
| 120 | - | path := filepath.Join(directory, "control.sock") | |||
| 121 | done := make(chan error, 1) | 128 | done := make(chan error, 1) | ||
| 122 | go func() { done <- r.serve("127.0.0.1:0", path) }() | 129 | go func() { done <- r.serve("127.0.0.1:0", path) }() | ||
| 123 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | 130 | require.Eventually(t, func() bool { _, err := os.Stat(path); return err == nil }, time.Second, time.Millisecond) | ||