package migration import ( "context" "io" "testing" "time" ) func TestProcessCancellation(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.Canceled { t.Fatalf("got %v", err) } ctx, cancel = context.WithTimeout(context.Background(), 50*time.Millisecond) defer cancel() start := time.Now() if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.DeadlineExceeded { t.Fatalf("got %v", err) } if time.Since(start) > 2*time.Second { t.Fatal("cancellation was too slow") } }