| 685 | } |
| 686 | |
| 687 | func TestProcGroupProcessExit(t *testing.T) { |
| 688 | t.Parallel() |
| 689 | |
| 690 | logger := slog.Make(sloghuman.Sink(&bytes.Buffer{})) |
| 691 | group := newProcGroup(t.Context(), logger) |
| 692 | |
| 693 | cmd := exec.CommandContext(t.Context(), "false") |
| 694 | cmd.Env = os.Environ() |
| 695 | require.NoError(t, group.Start("dies-fast", cmd)) |
| 696 | |
| 697 | // Process exit should cancel the group context. |
| 698 | select { |
| 699 | case <-group.Ctx().Done(): |
| 700 | case <-time.After(5 * time.Second): |
| 701 | t.Fatal("timed out waiting for context cancellation") |
| 702 | } |
| 703 | |
| 704 | // Wait should return an error naming the exited process. |
| 705 | err := group.Wait() |
| 706 | require.Error(t, err) |
| 707 | assert.Contains(t, err.Error(), "dies-fast") |
| 708 | } |
| 709 | |
| 710 | func TestProcGroupGracefulShutdown(t *testing.T) { |
| 711 | t.Parallel() |