From f672e963c8c00aa57852b0b49289f08874a791f1 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Mon, 23 Nov 2026 21:12:35 +0100 Subject: [PATCH 1/3] vm: set the file-size limit in a child, not in the test process TestAFlushPastTheFileSizeLimitRaises lowered RLIMIT_FSIZE to 4 bytes in the test process itself. The limit is per process, so every file written while it held, by the other tests or by the testing package, was refused too: the arm64 lane of go-embedded-ruby/ruby#982 failed with "can't write .../testlog.txt: file too large" after every test had passed. The limited flush now runs in a child copy of the test binary, which reports the class it raised on stdout. Negative control: leaving the child's limit unchanged makes the test fail ("fsize: raised " with no class). Co-Authored-By: Claude Opus 5.5 --- internal/vm/io_dirty_fsize_internal_test.go | 52 ++++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/internal/vm/io_dirty_fsize_internal_test.go b/internal/vm/io_dirty_fsize_internal_test.go index 0ffd1ed1..4983b76b 100644 --- a/internal/vm/io_dirty_fsize_internal_test.go +++ b/internal/vm/io_dirty_fsize_internal_test.go @@ -7,33 +7,61 @@ package vm import ( + "os" + "os/exec" "path/filepath" + "strings" "syscall" "testing" ) +// fsizeChildEnv marks the copy of the test binary that runs the limited flush. +const fsizeChildEnv = "RBGO_FSIZE_CHILD" + // TestAFlushPastTheFileSizeLimitRaises: the file opened, and the write itself // was refused. With RLIMIT_FSIZE below the span's offset, write(2) answers // EFBIG (the Go runtime ignores SIGXFSZ, so the process survives it). This is // TestAFlushThatCannotWriteRaises for platforms with no /dev/full: the error // must be raised, not dropped while Close reports success. +// +// The limit is set in a CHILD copy of the test binary, never in this one. +// RLIMIT_FSIZE is per process: lowered here, it bound every file the other +// tests and the testing package wrote meanwhile, and the arm64 lane failed +// with "can't write .../testlog.txt: file too large" after every test had +// passed (go-embedded-ruby/ruby#982's first run). func TestAFlushPastTheFileSizeLimitRaises(t *testing.T) { - path := filepath.Join(t.TempDir(), "f") + if os.Getenv(fsizeChildEnv) == "1" { + fsizeChild() + return + } + cmd := exec.Command(os.Args[0], "-test.run=^TestAFlushPastTheFileSizeLimitRaises$") + cmd.Env = append(os.Environ(), fsizeChildEnv+"=1", "TMPDIR="+t.TempDir()) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("child: %v\n%s", err, out) + } + switch got := string(out); { + case strings.Contains(got, "fsize: skip"): + t.Skipf("child could not arrange the limit:\n%s", got) + case !strings.Contains(got, "fsize: raised Errno::EFBIG\n"): + t.Errorf("a flush past RLIMIT_FSIZE did not raise Errno::EFBIG; child said:\n%s", got) + } +} + +// fsizeChild runs in the child: it lowers its own RLIMIT_FSIZE, flushes, and +// prints the class raised. Nothing else runs in this process. +func fsizeChild() { + path := filepath.Join(os.TempDir(), "f") o := &IOObj{isStr: true, writable: true, dirty: []ioSpan{{8, 12}}, path: path, buf: []byte("0123456789ab")} var old syscall.Rlimit if err := syscall.Getrlimit(syscall.RLIMIT_FSIZE, &old); err != nil { - t.Skipf("getrlimit: %v", err) + os.Stdout.WriteString("fsize: skip getrlimit: " + err.Error() + "\n") + return } - limited := old - limited.Cur = 4 + limited := syscall.Rlimit{Cur: 4, Max: old.Max} if err := syscall.Setrlimit(syscall.RLIMIT_FSIZE, &limited); err != nil { - t.Skipf("setrlimit: %v", err) - } - got := catchRaise(func() { ioFlush(o) }) - if err := syscall.Setrlimit(syscall.RLIMIT_FSIZE, &old); err != nil { - t.Fatalf("restoring RLIMIT_FSIZE: %v", err) - } - if got != "Errno::EFBIG" { - t.Errorf("a flush past RLIMIT_FSIZE raised %q, want Errno::EFBIG", got) + os.Stdout.WriteString("fsize: skip setrlimit: " + err.Error() + "\n") + return } + os.Stdout.WriteString("fsize: raised " + catchRaise(func() { ioFlush(o) }) + "\n") } From b1d28744e6b5ffcff79bbfb0a35951931318beb6 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sat, 28 Nov 2026 20:20:39 +0100 Subject: [PATCH 2/3] test: restore RLIMIT_FSIZE in the child before it exits The child printed "fsize: raised Errno::EFBIG" and PASS, then failed writing its own coverage data under -cover ("file too large") and exited with status 2 on the ubuntu and macos lanes. The limit is now restored right after the flush raised, before anything else in the child writes. Co-Authored-By: Claude Opus 5.5 --- internal/vm/io_dirty_fsize_internal_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/vm/io_dirty_fsize_internal_test.go b/internal/vm/io_dirty_fsize_internal_test.go index 4983b76b..b07a663b 100644 --- a/internal/vm/io_dirty_fsize_internal_test.go +++ b/internal/vm/io_dirty_fsize_internal_test.go @@ -63,5 +63,12 @@ func fsizeChild() { os.Stdout.WriteString("fsize: skip setrlimit: " + err.Error() + "\n") return } - os.Stdout.WriteString("fsize: raised " + catchRaise(func() { ioFlush(o) }) + "\n") + got := catchRaise(func() { ioFlush(o) }) + // Restore it before anything else writes: the child still has its own + // files to write on the way out (the coverage data, under -cover, which + // is what failed on the CI lanes while the flush had raised EFBIG). + if err := syscall.Setrlimit(syscall.RLIMIT_FSIZE, &old); err != nil { + os.Stdout.WriteString("fsize: restoring RLIMIT_FSIZE: " + err.Error() + "\n") + } + os.Stdout.WriteString("fsize: raised " + got + "\n") } From e72518e212b02692e18d13f208a21b1ce3256abb Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sat, 28 Nov 2026 21:54:55 +0100 Subject: [PATCH 3/3] test: let the fsize child's coverage reach the profile The EFBIG arm of writeDirty is reached only in the child on macOS (no /dev/full there), and the child was started without -test.gocoverdir, so its counters were dropped and the coverage ratchet failed the macos lane: "internal/vm/io_dirty.go writeDirty 89.5% (was fully covered)". The parent now passes its own -test.gocoverdir on; the testing package merges every counter file in that directory into the profile. Co-Authored-By: Claude Opus 5.5 --- internal/vm/io_dirty_fsize_internal_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/vm/io_dirty_fsize_internal_test.go b/internal/vm/io_dirty_fsize_internal_test.go index b07a663b..f9c097f1 100644 --- a/internal/vm/io_dirty_fsize_internal_test.go +++ b/internal/vm/io_dirty_fsize_internal_test.go @@ -7,6 +7,7 @@ package vm import ( + "flag" "os" "os/exec" "path/filepath" @@ -34,7 +35,16 @@ func TestAFlushPastTheFileSizeLimitRaises(t *testing.T) { fsizeChild() return } - cmd := exec.Command(os.Args[0], "-test.run=^TestAFlushPastTheFileSizeLimitRaises$") + args := []string{"-test.run=^TestAFlushPastTheFileSizeLimitRaises$"} + // Under -cover the child's counters must land where this process's do: + // the testing package merges every counter file in -test.gocoverdir into + // the profile, and the EFBIG arm of writeDirty is reached ONLY in the + // child on macOS (no /dev/full). Without this the coverage ratchet saw the + // arm as unreached (go-embedded-ruby/ruby#983's macos lane). + if f := flag.Lookup("test.gocoverdir"); f != nil && f.Value.String() != "" { + args = append(args, "-test.gocoverdir="+f.Value.String()) + } + cmd := exec.Command(os.Args[0], args...) cmd.Env = append(os.Environ(), fsizeChildEnv+"=1", "TMPDIR="+t.TempDir()) out, err := cmd.CombinedOutput() if err != nil {