MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestBashParentCancelMidRun

Function TestBashParentCancelMidRun

internal/tools/bash_test.go:183–201  ·  view source on GitHub ↗

TestBashParentCancelMidRun: parent cancel mid-sleep returns "(cancelled)", not a misleading "(timeout after Xs)" or stale exit code. Parent cancel always wins over timeout: it's the user's signal.

(t *testing.T)

Source from the content-addressed store, hash-verified

181// not a misleading "(timeout after Xs)" or stale exit code. Parent cancel
182// wins when it fires before the deadline: it's the user's signal (a latched
183// DeadlineExceeded still labels as timeout, since the timeout killed first).
184func TestBashParentCancelMidRun(t *testing.T) {
185 parent, cancel := context.WithCancel(context.Background())
186 go func() {
187 time.Sleep(50 * time.Millisecond)
188 cancel()
189 }()
190 start := time.Now()
191 out := Bash(parent, "sleep 5", 10*time.Second)
192 elapsed := time.Since(start)
193 if elapsed > 2*time.Second {
194 t.Fatalf("parent cancel didn't propagate; elapsed %s", elapsed)
195 }
196 if !strings.Contains(out, "cancelled") {
197 t.Fatalf("expected (cancelled) marker, got %q", out)
198 }
199 if strings.Contains(out, "timeout") {
200 t.Fatalf("parent-cancel must not be reported as timeout: %q", out)
201 }
202}
203
204func TestBashBackgroundedChildDoesNotBlock(t *testing.T) {

Callers

nothing calls this directly

Calls 1

BashFunction · 0.85

Tested by

no test coverage detected