-
Notifications
You must be signed in to change notification settings - Fork 14
test: stabilize unix socket test paths #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,17 +54,23 @@ | |
| if cfg.MaxInFlight == 0 { | ||
| cfg.MaxInFlight = 1 | ||
| } | ||
| if cfg.MaxInFlightPerWorker == 0 { | ||
| cfg.MaxInFlightPerWorker = 1 | ||
|
Comment on lines
+57
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This helper now assigns Useful? React with 👍 / 👎. |
||
| } | ||
| p := &Pool{ | ||
| opts: PoolOptions{Config: cfg}, | ||
| logger: NewLogger(LoggingConfig{Level: "error", Format: "json"}), | ||
| workers: make([]*poolWorker, len(workers)), | ||
| semaphore: make(chan struct{}, cfg.Workers*cfg.MaxInFlight), | ||
| activeRequests: make(map[uint64]*activeRequest), | ||
| opts: PoolOptions{Config: cfg}, | ||
| logger: NewLogger(LoggingConfig{Level: "error", Format: "json"}), | ||
| workers: make([]*poolWorker, len(workers)), | ||
| semaphore: make(chan struct{}, cfg.MaxInFlight), | ||
| workerAvailable: make(chan struct{}, cfg.Workers*cfg.MaxInFlightPerWorker), | ||
|
Check failure on line 65 in pkg/pyproc/pool_test.go
|
||
| shutdownCh: make(chan struct{}), | ||
|
Comment on lines
60
to
+66
|
||
| activeRequests: make(map[uint64]*activeRequest), | ||
| } | ||
| for i, w := range workers { | ||
| p.workers[i] = &poolWorker{ | ||
| worker: w, | ||
| connPool: make(chan net.Conn, cfg.MaxInFlight), | ||
| worker: w, | ||
| connPool: make(chan net.Conn, cfg.MaxInFlightPerWorker), | ||
| inflightGate: make(chan struct{}, cfg.MaxInFlightPerWorker), | ||
|
Check failure on line 73 in pkg/pyproc/pool_test.go
|
||
| } | ||
| } | ||
| return p | ||
|
|
@@ -189,8 +195,7 @@ | |
| } | ||
|
|
||
| func TestPoolStartPrepopulateAndHealth(t *testing.T) { | ||
| tmp := t.TempDir() | ||
| paths := []string{filepath.Join(tmp, "w0.sock"), filepath.Join(tmp, "w1.sock")} | ||
| paths := []string{tempSocketPath(t, "prepop-w0"), tempSocketPath(t, "prepop-w1")} | ||
| servers := []func(){ | ||
| startUnixServer(t, paths[0], func(req protocol.Request) *protocol.Response { | ||
| resp, _ := protocol.NewResponse(req.ID, map[string]string{"ok": "yes"}) | ||
|
|
@@ -333,7 +338,7 @@ | |
| } | ||
|
|
||
| func TestPoolCallCreatesConnectionAndReturns(t *testing.T) { | ||
| path := "/tmp/pool-creates-conn.sock" | ||
| path := tempSocketPath(t, "pool-create-conn") | ||
| stop := startUnixServer(t, path, func(req protocol.Request) *protocol.Response { | ||
| resp, _ := protocol.NewResponse(req.ID, map[string]string{"ok": "yes"}) | ||
| return resp | ||
|
|
@@ -551,7 +556,7 @@ | |
| } | ||
|
|
||
| func TestPoolConnect(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "connect.sock") | ||
| path := tempSocketPath(t, "connect") | ||
| stop := startUnixServer(t, path, func(req protocol.Request) *protocol.Response { | ||
| resp, _ := protocol.NewResponse(req.ID, map[string]string{"ok": "yes"}) | ||
| return resp | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package pyproc | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func tempSocketPath(t *testing.T, prefix string) string { | ||
| t.Helper() | ||
| base := filepath.Join(os.TempDir(), "pyproc") | ||
| if err := os.MkdirAll(base, 0755); err != nil { | ||
| t.Fatalf("failed to create temp dir: %v", err) | ||
| } | ||
| name := fmt.Sprintf("%s-%d.sock", prefix, time.Now().UnixNano()) | ||
| return filepath.Join(base, name) | ||
|
Comment on lines
+13
to
+18
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
| "net" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
@@ -12,7 +13,11 @@ import ( | |
| // It uses /tmp directly to avoid macOS socket path length limits. | ||
| func startTestUnixListener(t *testing.T) (net.Listener, string) { | ||
| t.Helper() | ||
| f, err := os.CreateTemp("/tmp", "pyproc-test-*.sock") | ||
| baseDir := filepath.Join(os.TempDir(), "pyproc") | ||
| if err := os.MkdirAll(baseDir, 0755); err != nil { | ||
| t.Fatalf("failed to create temp dir: %v", err) | ||
| } | ||
| f, err := os.CreateTemp(baseDir, "pyproc-test-*.sock") | ||
|
Comment on lines
13
to
+20
|
||
| if err != nil { | ||
| t.Fatalf("failed to create temp file: %v", err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a predictable shared temp directory with permissions
0755in a potentially shared temp location can be avoided in tests by using a per-process/per-test directory (os.MkdirTemport.TempDir) when possible, or by using more restrictive permissions (commonly0700) for user-owned temp dirs. If the shared dir is needed to keep paths short, consider tightening permissions and/or centralizing this logic via the same helper used elsewhere to reduce duplication across tests.