Skip to content
quarry Artifact [e9c710490c]
Login

Artifact [e9c710490c]

Artifact e9c710490cd7b2ed15d3f9d07f616d413dafa5dff779e92416767776b0912b90:


//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")
}