Skip to content

Commit

Permalink
Travis: apply timeout multiplier on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mpl committed Jun 3, 2020
1 parent f1cff30 commit 74479d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ matrix:
env:
global:
- GO111MODULE=on
- CI=1

go_import_path: github.com/containous/yaegi

Expand Down
26 changes: 25 additions & 1 deletion cmd/yaegi/yaegi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"testing"
"time"
)

const (
// CITimeoutMultiplier is the multiplier for all timeouts in the CI
CITimeoutMultiplier = 3
)

// Sleep pauses the current goroutine for at least the duration d.
func Sleep(d time.Duration) {
d = applyCIMultiplier(d)
time.Sleep(d)
}

func applyCIMultiplier(timeout time.Duration) time.Duration {
ci := os.Getenv("CI")
if ci == "" {
return timeout
}
b, err := strconv.ParseBool(ci)
if err != nil || !b {
return timeout
}
return time.Duration(float64(timeout) * CITimeoutMultiplier)
}

func TestYaegiCmdCancel(t *testing.T) {
tmp, err := ioutil.TempDir("", "yaegi-")
if err != nil {
Expand Down Expand Up @@ -56,7 +80,7 @@ func TestYaegiCmdCancel(t *testing.T) {
if err != nil {
t.Errorf("failed pipe test source to yaegi command: %v", err)
}
time.Sleep(100 * time.Millisecond)
Sleep(200 * time.Millisecond)
err = cmd.Process.Signal(os.Interrupt)
if err != nil {
t.Errorf("failed to send os.Interrupt to yaegi command: %v", err)
Expand Down

0 comments on commit 74479d7

Please sign in to comment.