mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* test(volume_server): wait out a server's disk I/O before calling its SIGINT exit a hang stopProcess gave every server 10s to exit after SIGINT. On a CI runner with a busy disk, the fsync in volume close can take longer than that: the server is in uninterruptible sleep, not hung. Sample the server's threads from /proc while waiting. Once one has been in D state, allow up to a minute. A server that never touched the disk still fails at 10s, and the failure now lists its threads' states and wait channels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(volume_server): wait for the sleep child before checking its stop Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(volume_server): reap the SIGINT-ignoring child if it never starts sleeping Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package framework
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type errorRecorder struct {
|
|
testing.TB
|
|
errs []string
|
|
}
|
|
|
|
func (r *errorRecorder) Errorf(format string, args ...any) {
|
|
r.errs = append(r.errs, fmt.Sprintf(format, args...))
|
|
}
|
|
|
|
func TestStopProcessReportsTheThreadsOfAServerIgnoringSIGINT(t *testing.T) {
|
|
if runtime.GOOS != "linux" {
|
|
t.Skip("thread states come from /proc")
|
|
}
|
|
defer func(d time.Duration) { stopTimeout = d }(stopTimeout)
|
|
stopTimeout = 200 * time.Millisecond
|
|
|
|
cmd := exec.Command("sh", "-c", `trap "" INT; exec sleep 30`)
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatalf("start: %v", err)
|
|
}
|
|
defer func() {
|
|
_ = cmd.Process.Kill()
|
|
_ = cmd.Wait()
|
|
}()
|
|
waitForSleepThread(t, cmd.Process.Pid)
|
|
rec := &errorRecorder{TB: t}
|
|
stopProcess(rec, "server", cmd)
|
|
|
|
if len(rec.errs) != 1 || !strings.Contains(rec.errs[0], "server did not exit within") || !strings.Contains(rec.errs[0], "1x[sleep S ") {
|
|
t.Fatalf("errors = %q", rec.errs)
|
|
}
|
|
}
|
|
|
|
func TestProcessThreadsFindsNoDiskWaitInAnIdleProcess(t *testing.T) {
|
|
if runtime.GOOS != "linux" {
|
|
t.Skip("thread states come from /proc")
|
|
}
|
|
cmd := exec.Command("sleep", "30")
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatalf("start: %v", err)
|
|
}
|
|
defer func() {
|
|
_ = cmd.Process.Kill()
|
|
_ = cmd.Wait()
|
|
}()
|
|
waitForSleepThread(t, cmd.Process.Pid)
|
|
|
|
threads, inDiskWait := processThreads(cmd.Process.Pid)
|
|
if inDiskWait || !strings.HasPrefix(threads, "1x[sleep S ") {
|
|
t.Fatalf("threads = %q, inDiskWait = %v", threads, inDiskWait)
|
|
}
|
|
}
|
|
|
|
// waitForSleepThread waits until pid has exec'd sleep and is sleeping, so
|
|
// a SIGINT trap set before the exec is in place.
|
|
func waitForSleepThread(t *testing.T, pid int) {
|
|
t.Helper()
|
|
deadline := time.Now().Add(5 * time.Second)
|
|
for {
|
|
threads, _ := processThreads(pid)
|
|
if strings.HasPrefix(threads, "1x[sleep S ") {
|
|
return
|
|
}
|
|
if time.Now().After(deadline) {
|
|
t.Fatalf("pid %d never reached sleep: %q", pid, threads)
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
}
|