package xfer
import (
"os"
"testing"
)
// A second quarry on the host must leave the first one's children
// alone: only a match whose parent is init is an orphan (quarry#448).
func TestReapKillsOnlyChildrenOfInit(t *testing.T) {
parents := map[int]int{100: 1, 200: 4242, 300: 1}
var killed []int
n := reapOrphans([]int{100, 200, 300, 400},
func(pid int) (int, bool) { pp, ok := parents[pid]; return pp, ok },
func(pid int) bool { killed = append(killed, pid); return true })
if n != 2 || len(killed) != 2 || killed[0] != 100 || killed[1] != 300 {
t.Errorf("FAIL: killed %v (n=%d), want [100 300]: a live parent survives, an unknown pid is skipped", killed, n)
}
if !t.Failed() {
t.Log("ok")
}
}
func TestParentPIDReadsTheRealParent(t *testing.T) {
pp, ok := parentPID(os.Getpid())
if !ok || pp != os.Getppid() {
t.Errorf("FAIL: parentPID(self) = %d, %v; want %d", pp, ok, os.Getppid())
}
if !t.Failed() {
t.Log("ok")
}
}