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)
| 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). |
| 184 | func 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 | |
| 204 | func TestBashBackgroundedChildDoesNotBlock(t *testing.T) { |