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

Callers

nothing calls this directly

Calls 1

BashFunction · 0.85

Tested by

no test coverage detected