Restrict TestDocker commands to 10 minutes of total runtime. (#3350)

* Restrict TestDocker commands to 10 minutes of total runtime.
* Hide unneccesarily scary delete error
pull/3286/head
Thomas Strömberg 2018-11-27 08:24:28 -08:00 committed by Balint Pato
parent 41bd1de699
commit e0df20f294
2 changed files with 40 additions and 16 deletions

View File

@ -19,36 +19,53 @@ limitations under the License.
package integration
import (
"context"
"fmt"
"strings"
"testing"
"time"
)
func TestDocker(t *testing.T) {
minikubeRunner := NewMinikubeRunner(t)
if strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") {
mk := NewMinikubeRunner(t)
if strings.Contains(mk.StartArgs, "--vm-driver=none") {
t.Skip("skipping test as none driver does not bundle docker")
}
minikubeRunner.RunCommand("delete", false)
startCmd := fmt.Sprintf("start %s %s %s", minikubeRunner.StartArgs, minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
minikubeRunner.RunCommand(startCmd, true)
minikubeRunner.EnsureRunning()
// Start a timer for all remaining commands, to display failure output before a panic.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
// Pre-cleanup: this usually fails, because no instance is running.
mk.RunWithContext(ctx, "delete")
startCmd := fmt.Sprintf("start %s %s %s", mk.StartArgs, mk.Args,
"--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true")
out, err := mk.RunWithContext(ctx, startCmd)
if err != nil {
t.Fatalf("start: %v\nstart out: %s", err, out)
}
mk.EnsureRunning()
out, err = mk.RunWithContext(ctx, "ssh -- systemctl show docker --property=Environment --no-pager")
if err != nil {
t.Errorf("docker env: %v\ndocker env out: %s", err, out)
}
dockerdEnvironment := minikubeRunner.RunCommand("ssh -- systemctl show docker --property=Environment --no-pager", true)
fmt.Println(dockerdEnvironment)
for _, envVar := range []string{"FOO=BAR", "BAZ=BAT"} {
if !strings.Contains(dockerdEnvironment, envVar) {
t.Fatalf("Env var %s missing from Environment: %s.", envVar, dockerdEnvironment)
if !strings.Contains(string(out), envVar) {
t.Errorf("Env var %s missing: %s.", envVar, out)
}
}
dockerdExecStart := minikubeRunner.RunCommand("ssh -- systemctl show docker --property=ExecStart --no-pager", true)
fmt.Println(dockerdExecStart)
out, err = mk.RunWithContext(ctx, "ssh -- systemctl show docker --property=ExecStart --no-pager")
if err != nil {
t.Errorf("ssh show docker: %v\nshow docker out: %s", err, out)
}
for _, opt := range []string{"--debug", "--icc=true"} {
if !strings.Contains(dockerdExecStart, opt) {
t.Fatalf("Option %s missing from ExecStart: %s.", opt, dockerdExecStart)
if !strings.Contains(string(out), opt) {
t.Fatalf("Option %s missing from ExecStart: %s.", opt, out)
}
}
}

View File

@ -19,6 +19,7 @@ package util
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"math/rand"
@ -30,7 +31,6 @@ import (
"time"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/minikube/pkg/minikube/assets"
commonutil "k8s.io/minikube/pkg/util"
@ -81,6 +81,13 @@ func (m *MinikubeRunner) RunCommand(command string, checkError bool) string {
return string(stdout)
}
// RunWithContext calls the minikube command with a context, useful for timeouts.
func (m *MinikubeRunner) RunWithContext(ctx context.Context, command string) ([]byte, error) {
commandArr := strings.Split(command, " ")
path, _ := filepath.Abs(m.BinaryPath)
return exec.CommandContext(ctx, path, commandArr...).CombinedOutput()
}
func (m *MinikubeRunner) RunDaemon(command string) (*exec.Cmd, *bufio.Reader) {
commandArr := strings.Split(command, " ")
path, _ := filepath.Abs(m.BinaryPath)