Time out commands after three minutes

This means we get to see their output up to the point they timed out,
and also means that we avoid CircleCI killing the entire job after
five minutes of inactivity.
This commit is contained in:
Bryan Boreham
2016-06-10 17:53:36 +01:00
parent 2da55ceef2
commit f2e40b45c8

View File

@@ -33,6 +33,7 @@ var (
useScheduler = false useScheduler = false
runParallel = false runParallel = false
verbose = false verbose = false
timeout = 180 // In seconds. Three minutes ought to be enough for any test
consoleLock = sync.Mutex{} consoleLock = sync.Mutex{}
) )
@@ -96,7 +97,16 @@ func (t test) run(hosts []string) bool {
} }
start := time.Now() start := time.Now()
err := cmd.Run() var err error
c := make(chan error, 1)
go func() { c <- cmd.Run() }()
select {
case err = <-c:
case <-time.After(time.Duration(timeout) * time.Second):
err = fmt.Errorf("timed out")
}
duration := float64(time.Now().Sub(start)) / float64(time.Second) duration := float64(time.Now().Sub(start)) / float64(time.Second)
consoleLock.Lock() consoleLock.Lock()
@@ -245,6 +255,7 @@ func main() {
mflag.BoolVar(&runParallel, []string{"parallel"}, false, "Run tests in parallel on hosts where possible") mflag.BoolVar(&runParallel, []string{"parallel"}, false, "Run tests in parallel on hosts where possible")
mflag.BoolVar(&verbose, []string{"v"}, false, "Print output from all tests (Also enabled via DEBUG=1)") mflag.BoolVar(&verbose, []string{"v"}, false, "Print output from all tests (Also enabled via DEBUG=1)")
mflag.StringVar(&schedulerHost, []string{"scheduler-host"}, defaultSchedulerHost, "Hostname of scheduler.") mflag.StringVar(&schedulerHost, []string{"scheduler-host"}, defaultSchedulerHost, "Hostname of scheduler.")
mflag.IntVar(&timeout, []string{"timeout"}, 180, "Max time to run one test for, in seconds")
mflag.Parse() mflag.Parse()
if len(os.Getenv("DEBUG")) > 0 { if len(os.Getenv("DEBUG")) > 0 {