Skip to content

Commit 6179ea4

Browse files
committed
fix: stabilize mac rc gate tests
1 parent 91546a8 commit 6179ea4

8 files changed

Lines changed: 81 additions & 29 deletions

File tree

cmd/gc/cmd_citystatus_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ func TestControllerStatusForCityPrefersRegisteredSupervisorState(t *testing.T) {
488488
t.Fatalf("register city: %v", err)
489489
}
490490

491-
sockPath := filepath.Join(cityPath, ".gc", "controller.sock")
491+
sockPath := controllerSocketPath(cityPath)
492+
if err := os.MkdirAll(filepath.Dir(sockPath), 0o755); err != nil {
493+
t.Fatal(err)
494+
}
492495
lis, err := net.Listen("unix", sockPath)
493496
if err != nil {
494497
t.Fatal(err)
@@ -540,7 +543,10 @@ func TestControllerStatusForCityFallsBackToStandaloneWhenRegisteredSupervisorDow
540543
t.Fatalf("register city: %v", err)
541544
}
542545

543-
sockPath := filepath.Join(cityPath, ".gc", "controller.sock")
546+
sockPath := controllerSocketPath(cityPath)
547+
if err := os.MkdirAll(filepath.Dir(sockPath), 0o755); err != nil {
548+
t.Fatal(err)
549+
}
544550
lis, err := net.Listen("unix", sockPath)
545551
if err != nil {
546552
t.Fatal(err)
@@ -627,7 +633,10 @@ func TestControllerStatusForCityFallsBackToStandaloneWhenSupervisorVanishesDurin
627633
t.Fatalf("register city: %v", err)
628634
}
629635

630-
sockPath := filepath.Join(cityPath, ".gc", "controller.sock")
636+
sockPath := controllerSocketPath(cityPath)
637+
if err := os.MkdirAll(filepath.Dir(sockPath), 0o755); err != nil {
638+
t.Fatal(err)
639+
}
631640
lis, err := net.Listen("unix", sockPath)
632641
if err != nil {
633642
t.Fatal(err)

cmd/gc/cmd_register_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func TestDoRegister(t *testing.T) {
4343
if err != nil {
4444
t.Fatal(err)
4545
}
46-
// Registry.Register resolves symlinks (e.g. /var → /private/var on macOS).
47-
resolvedCityPath, _ := filepath.EvalSymlinks(cityPath)
46+
// Registry.Register stores the same canonical comparison form used by
47+
// runtime path comparisons.
48+
resolvedCityPath := canonicalTestPath(cityPath)
4849
if len(entries) != 1 || entries[0].Path != resolvedCityPath {
4950
t.Errorf("expected 1 entry at %s, got %v", resolvedCityPath, entries)
5051
}

cmd/gc/cmd_supervisor_city_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ func TestRegisterCityWithSupervisorWaitsForConfiguredStartupTimeout(t *testing.T
329329
if err != nil {
330330
t.Fatal(err)
331331
}
332-
// Registry.Register resolves symlinks (e.g. /var → /private/var on macOS),
333-
// so compare against the resolved path.
334-
resolvedCityPath, _ := filepath.EvalSymlinks(cityPath)
332+
// Registry.Register stores the same canonical comparison form used by
333+
// runtime path comparisons.
334+
resolvedCityPath := canonicalTestPath(cityPath)
335335
if len(entries) != 1 || entries[0].Path != resolvedCityPath {
336336
t.Fatalf("expected retained registry entry for %s, got %v", resolvedCityPath, entries)
337337
}
@@ -792,9 +792,9 @@ func TestUnregisterCityFromSupervisorRestoresRegistrationOnReloadFailure(t *test
792792
if err != nil {
793793
t.Fatal(err)
794794
}
795-
// Registry.Register resolves symlinks (e.g. /var → /private/var on macOS),
796-
// so compare against the resolved path.
797-
resolvedCityPath, _ := filepath.EvalSymlinks(cityPath)
795+
// Registry.Register stores the same canonical comparison form used by
796+
// runtime path comparisons.
797+
resolvedCityPath := canonicalTestPath(cityPath)
798798
if len(entries) != 1 || entries[0].Path != resolvedCityPath {
799799
t.Fatalf("expected restored registry entry for %s, got %v", resolvedCityPath, entries)
800800
}
@@ -1028,7 +1028,7 @@ func TestUnregisterCityFromSupervisorRestoresRegistrationWhenControllerStopWaitF
10281028
if err != nil {
10291029
t.Fatal(err)
10301030
}
1031-
resolvedCityPath, _ := filepath.EvalSymlinks(cityPath)
1031+
resolvedCityPath := canonicalTestPath(cityPath)
10321032
if len(entries) != 1 || entries[0].Path != resolvedCityPath {
10331033
t.Fatalf("expected restored registry entry for %s, got %v", resolvedCityPath, entries)
10341034
}

cmd/gc/dolt_process_inspection.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,41 @@ func cwdFromPlainLsofOutput(output string) (string, bool) {
156156

157157
func deletedDataInodeTargetsFromFormattedLsofOutput(output string) []string {
158158
var targets []string
159-
for _, line := range strings.Split(output, "\n") {
160-
if !strings.HasPrefix(line, "n") {
161-
continue
159+
var currentName string
160+
currentDeleted := false
161+
flush := func() {
162+
if currentName != "" && currentDeleted {
163+
targets = append(targets, currentName)
162164
}
163-
target := strings.TrimSpace(strings.TrimPrefix(line, "n"))
164-
if !strings.Contains(target, " (deleted)") {
165+
currentName = ""
166+
currentDeleted = false
167+
}
168+
169+
for _, line := range strings.Split(output, "\n") {
170+
if line == "" {
165171
continue
166172
}
167-
target = strings.TrimSuffix(target, " (deleted)")
168-
if target != "" {
169-
targets = append(targets, target)
173+
switch line[0] {
174+
case 'f':
175+
flush()
176+
case 'l':
177+
links := strings.TrimSpace(strings.TrimPrefix(line, "l"))
178+
if links == "0" {
179+
currentDeleted = true
180+
}
181+
case 'n':
182+
if currentName != "" {
183+
flush()
184+
}
185+
target := strings.TrimSpace(strings.TrimPrefix(line, "n"))
186+
if strings.Contains(target, " (deleted)") {
187+
currentDeleted = true
188+
target = strings.TrimSuffix(target, " (deleted)")
189+
}
190+
currentName = target
170191
}
171192
}
193+
flush()
172194
return targets
173195
}
174196

@@ -272,7 +294,7 @@ func deletedDataInodeTargetsFromLsof(pid int) []string {
272294
}
273295

274296
func deletedDataInodeTargetsFromFormattedLsof(pid int) []string {
275-
out, err := lsofOutput(2*time.Second, "-p", strconv.Itoa(pid), "+L1", "-Fn")
297+
out, err := lsofOutput(2*time.Second, "-p", strconv.Itoa(pid), "+L1", "-Fnl")
276298
if err != nil {
277299
return nil
278300
}

cmd/gc/dolt_process_inspection_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,13 @@ func TestDeletedDataInodeTargetsFromFormattedLsofIgnoresLiveNameRecords(t *testi
122122
t.Fatalf("deletedDataInodeTargetsFromFormattedLsofOutput returned live targets: %#v", targets)
123123
}
124124
}
125+
126+
func TestDeletedDataInodeTargetsFromFormattedLsofUsesZeroLinkCount(t *testing.T) {
127+
targets := deletedDataInodeTargetsFromFormattedLsofOutput("p123\nf4\nn/private/tmp/gc-city/.beads/dolt/held.db\nl0\n")
128+
if len(targets) != 1 {
129+
t.Fatalf("deletedDataInodeTargetsFromFormattedLsofOutput returned %d targets, want 1: %#v", len(targets), targets)
130+
}
131+
if !samePath(targets[0], "/tmp/gc-city/.beads/dolt/held.db") {
132+
t.Fatalf("target = %q, want held.db", targets[0])
133+
}
134+
}

internal/pidutil/pidutil.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package pidutil
44
import (
55
"errors"
66
"os"
7+
"os/exec"
78
"path/filepath"
89
"strconv"
910
"strings"
@@ -22,11 +23,20 @@ func Alive(pid int) bool {
2223
statPath := filepath.Join("/proc", strconv.Itoa(pid), "stat")
2324
data, err := os.ReadFile(statPath)
2425
if err != nil {
25-
return true
26+
return !psReportsZombie(pid)
2627
}
2728
fields := strings.Fields(string(data))
2829
if len(fields) >= 3 && fields[2] == "Z" {
2930
return false
3031
}
3132
return true
3233
}
34+
35+
func psReportsZombie(pid int) bool {
36+
out, err := exec.Command("ps", "-o", "stat=", "-p", strconv.Itoa(pid)).Output()
37+
if err != nil {
38+
return false
39+
}
40+
state := strings.TrimSpace(string(out))
41+
return strings.HasPrefix(state, "Z")
42+
}

internal/supervisor/registry_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func TestRegistryRegisterAndList(t *testing.T) {
4141
if len(entries) != 1 {
4242
t.Fatalf("expected 1 entry, got %d", len(entries))
4343
}
44-
// Register canonicalizes via filepath.EvalSymlinks; resolve expected
45-
// path so the comparison holds on macOS (/var → /private/var).
46-
wantCity, _ := filepath.EvalSymlinks(cityPath)
44+
// Register stores the same canonical comparison form used by runtime
45+
// path comparisons.
46+
wantCity := testutil.CanonicalPath(cityPath)
4747
if entries[0].Path != wantCity {
4848
t.Errorf("expected path %s, got %s", wantCity, entries[0].Path)
4949
}
@@ -168,9 +168,9 @@ func TestRegistryMultipleCities(t *testing.T) {
168168
if err != nil {
169169
t.Fatal(err)
170170
}
171-
// Register canonicalizes via filepath.EvalSymlinks; resolve expected
172-
// path so the comparison holds on macOS (/var → /private/var).
173-
wantPath2, _ := filepath.EvalSymlinks(path2)
171+
// Register stores the same canonical comparison form used by runtime
172+
// path comparisons.
173+
wantPath2 := testutil.CanonicalPath(path2)
174174
if len(entries) != 1 || entries[0].Path != wantPath2 {
175175
t.Errorf("expected only city-b, got %v", entries)
176176
}

internal/worker/workertest/phase2_fake_worker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333

3434
const (
3535
fakeStartupGateTimeout = 2 * time.Second
36-
fakeStartupLaunchBound = 500 * time.Millisecond
36+
fakeStartupLaunchBound = 750 * time.Millisecond
3737
fakeStartupPostControlOverhead = 250 * time.Millisecond
3838
fakeInteractionSignalBound = 2 * time.Second
3939
)

0 commit comments

Comments
 (0)