Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-9039: test(cli): stop the dev-env daemon profile test probing the real hashed port (#10370)

Jiayuan Zhang23b4821ca73a
diff --git a/server/cmd/multica/cmd_daemon_identity_test.go b/server/cmd/multica/cmd_daemon_identity_test.go
index 261c1ebc16..df04786454 100644
--- a/server/cmd/multica/cmd_daemon_identity_test.go
+++ b/server/cmd/multica/cmd_daemon_identity_test.go
@@ -93,7 +93,13 @@ func serveHealthAsPID(t *testing.T, profile string, reports map[string]any, pid
if err != nil {
t.Skipf("health port %d for profile %q is busy on this machine: %v", port, profile, err)
}
- stub := &stubDaemon{port: port}
+ return serveStubDaemon(t, ln, reports, pid)
+}
+
+// serveStubDaemon serves the stub daemon on ln, which the stub then owns.
+func serveStubDaemon(t *testing.T, ln net.Listener, reports map[string]any, pid int) *stubDaemon {
+ t.Helper()
+ stub := &stubDaemon{port: ln.Addr().(*net.TCPAddr).Port}
body := map[string]any{"status": "running", "pid": pid, "uptime": "1h0m0s", "cli_version": "v0.4.23"}
for k, v := range reports {
diff --git a/server/cmd/multica/dev_env_profile_test.go b/server/cmd/multica/dev_env_profile_test.go
index 61188933d5..6a607979d1 100644
--- a/server/cmd/multica/dev_env_profile_test.go
+++ b/server/cmd/multica/dev_env_profile_test.go
@@ -1,6 +1,7 @@
package main
import (
+ "net"
"os"
"path/filepath"
"strings"
@@ -26,7 +27,7 @@ func setupDevEnvTask(t *testing.T) {
clearDaemonTaskEnv(t)
t.Setenv("MULTICA_TOKEN", "")
t.Setenv("MULTICA_SERVER_URL", "")
- t.Setenv("HOME", t.TempDir())
+ redirectTestHome(t, t.TempDir())
t.Setenv(devEnvHomeEnv, t.TempDir())
writeDevEnvManifest(t, devEnvTestName, "NAME="+devEnvTestName+"\nDIR=/tmp/checkout\nBACKEND_PORT="+devEnvTestPort+"\nPROFILE="+devEnvTestProfile+"\n")
@@ -85,10 +86,25 @@ func TestDevEnvDaemonProfileAllowedInsideTask(t *testing.T) {
if want := healthPortForProfile(profile); port != want {
t.Fatalf("status port = %d, want the profile's own %d", port, want)
}
- // The real command, end to end: nothing is running on the port.
+
+ // The real command, end to end, against a daemon this test owns.
+ // The daemon.port record steers stop off the hashed port, which
+ // another profile's daemon on this machine may already hold.
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ pid := startBlockingChild(t)
+ stub := serveStubDaemon(t, ln, map[string]any{"profile": profile}, pid)
+ if err := publishDaemonPort(profile, daemonPortRecord{Port: stub.port, PID: pid}); err != nil {
+ t.Fatal(err)
+ }
if err := runDaemonStop(cmd, nil); err != nil {
t.Fatalf("runDaemonStop --profile %s: %v", profile, err)
}
+ if got := stub.shutdownCount(); got != 1 {
+ t.Fatalf("stub daemon received %d shutdown requests, want 1", got)
+ }
})
}
}