Under WSL2 (magpie-desktop, kernel 5.15) a sleep's /proc/<pid>/status says "VmRSS: 0 kB" on the read right after its exec, before the loader maps anything. parseKiB counts 0 as no reading, and the test's wait loop stopped on the first !ok, so it failed at 0.00s every run there. A read a few ms later says 1792 kB. The loop now waits while there is no reading too, within the same 10s. Product code is unchanged: the one caller (claude_rss.go's oversized) reads a Claude Code after a whole turn, and a 0 there skips the check. What was run (this tree): - wsl-run go test -count=20 -run TestTreeRSS ./internal/proc/: ok (red 3 of 3 at origin/main before). - go test ./internal/proc/: ok on mote (6.1s) and on WSL (2.7s). Windows: TestTreeRSS passes; TestCombinedOutputOwnRuns and TestCombinedOutputOwnContext are red there at origin/main too (/bin/sh), fixed in the next commit. Refs #4033
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package proc
|
|
|
|
import (
|
|
"os/exec"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A running tree's resident memory is read, and none once it was waited
|
|
// for: its pid may be another process's by then.
|
|
func TestTreeRSS(t *testing.T) {
|
|
name, args := "sleep", []string{"30"}
|
|
if runtime.GOOS == "windows" {
|
|
name, args = "ping", []string{"-n", "30", "127.0.0.1"}
|
|
}
|
|
if _, err := exec.LookPath(name); err != nil {
|
|
t.Skip("no " + name)
|
|
}
|
|
tree, err := StartTree(exec.Command(name, args...))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// just after its exec a command holds a few pages, until its loader
|
|
// maps what it runs on (16KiB on ubuntu CI), so it is read until it
|
|
// does; under WSL2 the first read can say 0 kB, which isn't a reading
|
|
// (#4033)
|
|
rss, ok := tree.RSS()
|
|
for end := time.Now().Add(10 * time.Second); (!ok || rss < 64<<10) && time.Now().Before(end); {
|
|
time.Sleep(20 * time.Millisecond)
|
|
rss, ok = tree.RSS()
|
|
}
|
|
if !ok || rss < 64<<10 || rss > 1<<30 {
|
|
t.Fatalf("a running %s holds %d bytes (%v)", name, rss, ok)
|
|
}
|
|
tree.Kill()
|
|
_ = tree.Wait()
|
|
if _, ok := tree.RSS(); ok {
|
|
t.Fatal("a tree waited for was read")
|
|
}
|
|
if MemTotal() <= 0 && (runtime.GOOS == "darwin" || runtime.GOOS == "linux" || runtime.GOOS == "windows") {
|
|
t.Fatal("this computer's memory isn't known")
|
|
}
|
|
}
|