test(blockcheck): cover worker escalation and daemon preservation
Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
d508132b4f
commit
4d7e9743a2
1 file changed
+27
-1
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -29,15 +30,24 @@ func init() {
|
|||||||
if mode == "orphan" {
|
if mode == "orphan" {
|
||||||
if len(os.Args) == 2 && os.Args[1] == "--child" {
|
if len(os.Args) == 2 && os.Args[1] == "--child" {
|
||||||
signal.Ignore(syscall.SIGTERM)
|
signal.Ignore(syscall.SIGTERM)
|
||||||
|
fmt.Fprintln(os.Stdout, os.Getpid())
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Hour)
|
time.Sleep(time.Hour)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
child := exec.Command(os.Args[0], "--child")
|
child := exec.Command(os.Args[0], "--child")
|
||||||
|
ready, err := child.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
if err := child.Start(); err != nil {
|
if err := child.Start(); err != nil {
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
fmt.Fprintln(os.Stdout, child.Process.Pid)
|
line, err := bufio.NewReader(ready).ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(3)
|
||||||
|
}
|
||||||
|
fmt.Fprint(os.Stdout, line)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if len(os.Args) == 2 && os.Args[1] == "--child" {
|
if len(os.Args) == 2 && os.Args[1] == "--child" {
|
||||||
@@ -380,6 +390,22 @@ func TestBlockcheckCleansWorkersAfterSuccessfulLeader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDaemonCommandRetainsSuccessfulChild(t *testing.T) {
|
||||||
|
binary := fakeBlockcheck(t, "orphan")
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
if err := runBlockcheckCommand(context.Background(), binary, "", nil, &stdout, io.Discard); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
pid, err := strconv.Atoi(strings.TrimSpace(stdout.String()))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer syscall.Kill(pid, syscall.SIGKILL)
|
||||||
|
if err := syscall.Kill(pid, 0); err != nil {
|
||||||
|
t.Fatalf("daemon unexpectedly killed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w processReady) Write(p []byte) (int, error) {
|
func (w processReady) Write(p []byte) (int, error) {
|
||||||
pid, err := strconv.Atoi(strings.TrimSpace(string(p)))
|
pid, err := strconv.Atoi(strings.TrimSpace(string(p)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user