internal/processtest: set timeout

Updates #2571
This commit is contained in:
Hajime Hoshi 2023-02-18 17:36:03 +09:00
parent 01b97124c8
commit 0e57fc4c5f

View File

@ -18,10 +18,12 @@ package processtest_test
import ( import (
"bytes" "bytes"
"context"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"time"
exec "golang.org/x/sys/execabs" exec "golang.org/x/sys/execabs"
) )
@ -43,7 +45,10 @@ func TestPrograms(t *testing.T) {
} }
t.Run(n, func(t *testing.T) { t.Run(n, func(t *testing.T) {
cmd := exec.Command("go", "run", filepath.Join(dir, n)) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
cmd := exec.CommandContext(ctx, "go", "run", filepath.Join(dir, n))
stderr := &bytes.Buffer{} stderr := &bytes.Buffer{}
cmd.Stderr = stderr cmd.Stderr = stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {