Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 32 additions & 15 deletions test/integration/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we Fatalf instead of continuing the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in this case we'd lose valuable ExecStart testing methods, and would have to employ a whack-a-mole strategy for resolving test errors.

go/go-test-comments#keep-going covers this nicely:

"Even after your test cases encounter a failure, they should keep going for as long possible in order to print out all of the failed checks in a single run. This way, someone who's fixing the failing test doesn't have to play whac-a-mole, fixing one bug and then re-running the test to find the next bug.

On a practical level, prefer calling t.Error over t.Fatal. When comparing several different properties of a function's output, use t.Error for each of those comparisions.

t.Fatal is usually only appropriate when some piece of test setup fails, without which you cannot run the test at all."

}

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)
}
}
}
9 changes: 8 additions & 1 deletion test/integration/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"math/rand"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down