From c84f859dd028bd69f3b11ae976ce87681dd0207a Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 27 Oct 2026 00:18:41 +0800 Subject: [PATCH] pii: the GPU tests start pf-serve-vulkan off macOS, so they pass on Linux (#3741) TestFindJoinsTextsAndMapsBack, TestGPUDeathMovesToCPU, TestServeStartsWithoutResidencyHeartbeat and TestWarm were red on ubuntu CI (run 40351272355 at 80857a66c, and earlier). The cause: cebd0d4c3 made candidates() put a GPU pf-serve first only where there is one, pf-serve-vulkan or macOS's Metal pf-serve. The tests installed pf-serve alone and expected it on the GPU ("start pf-serve MTL0"), which holds on macOS only; on Linux it is the CPU's alone. gpuInstall installs macOS's pf-serve there and pf-serve-vulkan elsewhere, and says the GPU's start line; the four tests use it. The code isn't changed. Run: go test ./internal/pii/ (ok, macOS). The Linux branch forced on macOS (gpuInstall's darwin check made false, so pf-serve-vulkan is installed as on Linux): the four tests pass. GOOS=linux and GOOS=windows go vet ./internal/pii/ ok. Not tried: a Linux machine itself (no Docker daemon here); the next CI run is the check. --- internal/pii/main_test.go | 14 ++++++++++++++ internal/pii/serve_test.go | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/pii/main_test.go b/internal/pii/main_test.go index 8442c48e8..c766c0a3b 100644 --- a/internal/pii/main_test.go +++ b/internal/pii/main_test.go @@ -8,6 +8,7 @@ import ( "io" "os" "path/filepath" + "runtime" "strings" "testing" "time" @@ -196,6 +197,19 @@ func fakeInstall(t *testing.T, mode string, vulkan bool) string { return log } +// gpuInstall is fakeInstall with a GPU's pf-serve to start first: +// macOS's own, which runs on Metal, or elsewhere pf-serve-vulkan, as a +// computer with no Vulkan loader has none (#3741: these tests took +// macOS's for every system, and were red on Linux). It answers the line +// the stand-in logs as it starts there. +func gpuInstall(t *testing.T, mode string) (log, gpuStart string) { + t.Helper() + if runtime.GOOS == "darwin" { + return fakeInstall(t, mode, false), "start pf-serve MTL0" + } + return fakeInstall(t, mode, true), "start pf-serve-vulkan MTL0" +} + // fakeLines are the lines the stand-in logged that start with prefix. func fakeLines(t *testing.T, log, prefix string) []string { t.Helper() diff --git a/internal/pii/serve_test.go b/internal/pii/serve_test.go index eb678f6e3..e2dcbebc4 100644 --- a/internal/pii/serve_test.go +++ b/internal/pii/serve_test.go @@ -20,7 +20,7 @@ func person(s, e int) redact.Found { return redact.Found{Start: s, End: e, Label // comes back to each text at that text's own offsets; a text seen before // isn't asked about again. func TestFindJoinsTextsAndMapsBack(t *testing.T) { - log := fakeInstall(t, "ok", false) + log, _ := gpuInstall(t, "ok") texts := []string{"hi Alice", "nothing here", "Bob, Alice and Alice"} got, err := Find(texts) if err != nil { @@ -82,7 +82,7 @@ func TestWithinCutsSpansAtTheTextsEnds(t *testing.T) { // pf-serve that dies on the GPU is started again on the CPU, which the // request then gets its answer from, and stays there; the status says why. func TestGPUDeathMovesToCPU(t *testing.T) { - log := fakeInstall(t, "gpudies", false) + log, gpu := gpuInstall(t, "gpudies") got, err := Find([]string{"hi Alice"}) if err != nil { t.Fatal(err) @@ -90,7 +90,7 @@ func TestGPUDeathMovesToCPU(t *testing.T) { if !reflect.DeepEqual(got, [][]redact.Found{{person(3, 8)}}) { t.Fatalf("Find = %v", got) } - if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve MTL0", "start pf-serve CPU"}) { + if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{gpu, "start pf-serve CPU"}) { t.Fatalf("starts = %q", starts) } st := Now() @@ -295,7 +295,7 @@ func TestFailedModelHoldsRequestsBackAtOnce(t *testing.T) { // woke an idle one ~146 times a second (#3185). The CPU one after a GPU // death too. func TestServeStartsWithoutResidencyHeartbeat(t *testing.T) { - log := fakeInstall(t, "gpudies", false) + log, _ := gpuInstall(t, "gpudies") if _, err := Find([]string{"hi Alice"}); err != nil { t.Fatal(err) } @@ -351,7 +351,7 @@ func TestWarm(t *testing.T) { Warm() wait("no failure", func(s Status) bool { return strings.Contains(s.Failed, "can't load noload") }) - log := fakeInstall(t, "ok", false) + log, _ := gpuInstall(t, "ok") srv.failed = "before" Warm() wait("not running", func(s Status) bool { return s.Running && s.Device == "MTL0" && s.Failed == "" })