detached 5e09b48

test(crash): fail when the child exits before the kill and show its output

commit
5e09b48f81c3654292a06712e93998865e5b7fbc
author
brice · · 2026-10-10 03:15 UTC
parent
3755228
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +25 -5
M crash_test.go +25 -5
@@ -4,12 +4,14 @@ package kv
44
55 import (
66 "bytes"
7+ "errors"
78 "math/rand/v2"
89 "os"
910 "os/exec"
1011 "strconv"
1112 "strings"
1213 "sync"
14+ "syscall"
1315 "testing"
1416 "time"
1517 )
@@ -58,11 +60,13 @@ func TestCrashChild(t *testing.T) {
5860 }
5961 }
6062
61-// ackReader records the highest seq the child reported.
63+// ackReader records the highest seq the child reported and keeps every
64+// other line (test failures are written to stdout).
6265 type ackReader struct {
63- mu sync.Mutex
64- rest []byte
65- last int
66+ mu sync.Mutex
67+ rest []byte
68+ last int
69+ other strings.Builder
6670 }
6771
6872 func (a *ackReader) Write(p []byte) (int, error) {
@@ -76,11 +80,20 @@ func (a *ackReader) Write(p []byte) (int, error) {
7680 }
7781 if n, err := strconv.Atoi(string(line)); err == nil {
7882 a.last = max(a.last, n)
83+ } else {
84+ a.other.Write(line)
85+ a.other.WriteByte('\n')
7986 }
8087 a.rest = rest
8188 }
8289 }
8390
91+func (a *ackReader) output() string {
92+ a.mu.Lock()
93+ defer a.mu.Unlock()
94+ return a.other.String()
95+}
96+
8497 func (a *ackReader) lastAcked() int {
8598 a.mu.Lock()
8699 defer a.mu.Unlock()
@@ -120,7 +133,14 @@ func TestCrash(t *testing.T) {
120133 delay := time.Duration(20+rng.IntN(180)) * time.Millisecond
121134 time.Sleep(delay)
122135 _ = cmd.Process.Kill()
123- _ = cmd.Wait() // reports the kill; it also waits for the stdout copy
136+ // Wait also waits for the stdout copy. The child must have died from
137+ // the kill: an earlier exit means the writer itself failed.
138+ werr := cmd.Wait()
139+ var exitErr *exec.ExitError
140+ if !errors.As(werr, &exitErr) || exitErr.Sys().(syscall.WaitStatus).Signal() != syscall.SIGKILL {
141+ t.Fatalf("iteration %d: child did not die from SIGKILL (%v)\nchild output: %s\nchild stderr: %s",
142+ i, werr, acks.output(), stderr.String())
143+ }
124144 acked := acks.lastAcked()
125145
126146 db, err := Open(bg, dir, Options{})
@@ -4,12 +4,14 @@ package kv
4 4
5 import (5 import (
6 "bytes"6 "bytes"
7+ "errors"
7 "math/rand/v2"8 "math/rand/v2"
8 "os"9 "os"
9 "os/exec"10 "os/exec"
10 "strconv"11 "strconv"
11 "strings"12 "strings"
12 "sync"13 "sync"
14+ "syscall"
13 "testing"15 "testing"
14 "time"16 "time"
15 )17 )
@@ -58,11 +60,13 @@ func TestCrashChild(t *testing.T) {
58 }60 }
59 }61 }
60 62
61-// ackReader records the highest seq the child reported.63+// ackReader records the highest seq the child reported and keeps every
64+// other line (test failures are written to stdout).
62 type ackReader struct {65 type ackReader struct {
63- mu sync.Mutex66+ mu sync.Mutex
64- rest []byte67+ rest []byte
65- last int68+ last int
69+ other strings.Builder
66 }70 }
67 71
68 func (a *ackReader) Write(p []byte) (int, error) {72 func (a *ackReader) Write(p []byte) (int, error) {
@@ -76,11 +80,20 @@ func (a *ackReader) Write(p []byte) (int, error) {
76 }80 }
77 if n, err := strconv.Atoi(string(line)); err == nil {81 if n, err := strconv.Atoi(string(line)); err == nil {
78 a.last = max(a.last, n)82 a.last = max(a.last, n)
83+ } else {
84+ a.other.Write(line)
85+ a.other.WriteByte('\n')
79 }86 }
80 a.rest = rest87 a.rest = rest
81 }88 }
82 }89 }
83 90
91+func (a *ackReader) output() string {
92+ a.mu.Lock()
93+ defer a.mu.Unlock()
94+ return a.other.String()
95+}
96+
84 func (a *ackReader) lastAcked() int {97 func (a *ackReader) lastAcked() int {
85 a.mu.Lock()98 a.mu.Lock()
86 defer a.mu.Unlock()99 defer a.mu.Unlock()
@@ -120,7 +133,14 @@ func TestCrash(t *testing.T) {
120 delay := time.Duration(20+rng.IntN(180)) * time.Millisecond133 delay := time.Duration(20+rng.IntN(180)) * time.Millisecond
121 time.Sleep(delay)134 time.Sleep(delay)
122 _ = cmd.Process.Kill()135 _ = cmd.Process.Kill()
123- _ = cmd.Wait() // reports the kill; it also waits for the stdout copy136+ // Wait also waits for the stdout copy. The child must have died from
137+ // the kill: an earlier exit means the writer itself failed.
138+ werr := cmd.Wait()
139+ var exitErr *exec.ExitError
140+ if !errors.As(werr, &exitErr) || exitErr.Sys().(syscall.WaitStatus).Signal() != syscall.SIGKILL {
141+ t.Fatalf("iteration %d: child did not die from SIGKILL (%v)\nchild output: %s\nchild stderr: %s",
142+ i, werr, acks.output(), stderr.String())
143+ }
124 acked := acks.lastAcked()144 acked := acks.lastAcked()
125 145
126 db, err := Open(bg, dir, Options{})146 db, err := Open(bg, dir, Options{})

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 2

↑↓ moveenter openesc close