//go:build unix
package zitcli
import (
"context"
"os/exec"
"testing"
)
// A child killed by SIGKILL that its request did not cancel reads as
// the memory ceiling; one the request cancelled, or one that merely
// failed, does not.
func TestAKilledChildReadsAsOutOfMemory(t *testing.T) {
err := exec.Command("sh", "-c", "kill -9 $$").Run()
if !killedForMemory(context.Background(), err) {
t.Errorf("FAIL: a SIGKILLed child was not read as the memory ceiling: %v", err)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
if killedForMemory(ctx, err) {
t.Error("FAIL: a cancelled request's kill was read as the memory ceiling")
}
if killedForMemory(context.Background(), exec.Command("sh", "-c", "exit 1").Run()) {
t.Error("FAIL: an ordinary failure was read as the memory ceiling")
}
t.Log("ok")
}