Offset integration tests which start clusters by 5s

pull/5381/head
Thomas Stromberg 2019-09-17 07:08:57 -07:00
parent 062c472737
commit fff8f5cbec
7 changed files with 34 additions and 6 deletions

View File

@ -36,7 +36,7 @@ import (
// TestAddons tests addons that require no special environment -- in parallel
func TestAddons(t *testing.T) {
MaybeParallel(t)
MaybeSlowParallel(t)
profile := UniqueProfileName("addons")
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Minute)

View File

@ -30,7 +30,7 @@ func TestDockerFlags(t *testing.T) {
if NoneDriver() {
t.Skip("skipping: none driver does not support ssh or bundle docker")
}
MaybeParallel(t)
MaybeSlowParallel(t)
profile := UniqueProfileName("docker-flags")
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Minute)

View File

@ -27,7 +27,7 @@ import (
)
func TestGuestEnvironment(t *testing.T) {
MaybeParallel(t)
MaybeSlowParallel(t)
profile := UniqueProfileName("guest")
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer CleanupWithLogs(t, profile, cancel)

View File

@ -33,7 +33,7 @@ func TestGvisorAddon(t *testing.T) {
if NoneDriver() {
t.Skip("Can't run containerd backend with none driver")
}
MaybeParallel(t)
MaybeSlowParallel(t)
profile := UniqueProfileName("gvisor")
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Minute)

View File

@ -30,6 +30,7 @@ import (
"io/ioutil"
"os/exec"
"strings"
"sync"
"testing"
"time"
@ -40,6 +41,11 @@ import (
"k8s.io/minikube/pkg/kapi"
)
var (
antiRaceCounter = 0
antiRaceMutex = &sync.Mutex{}
)
// RunResult stores the result of an cmd.Run call
type RunResult struct {
Stdout *bytes.Buffer
@ -62,6 +68,7 @@ func (rr RunResult) Command() string {
return sb.String()
}
// Output returns human-readable output for an execution result
func (rr RunResult) Output() string {
var sb strings.Builder
if rr.Stdout.Len() > 0 {
@ -324,6 +331,27 @@ func MaybeParallel(t *testing.T) {
t.Parallel()
}
// MaybeSlowParallel is a terrible workaround for tests which start clusters in a race-filled world
// TODO: Try removing this hack once certificates are deployed per-profile
func MaybeSlowParallel(t *testing.T) {
// NoneDriver shouldn't parallelize "minikube start"
if NoneDriver() {
return
}
antiRaceMutex.Lock()
antiRaceCounter++
antiRaceMutex.Unlock()
if antiRaceCounter > 0 {
// Slow enough to offset start, but not slow to be a major source of delay
penalty := time.Duration(5*antiRaceCounter) * time.Second
t.Logf("MaybeSlowParallel: Sleeping %s to avoid start race ...", penalty)
time.Sleep(penalty)
}
t.Parallel()
}
// killProcessFamily kills a pid and all of its children
func killProcessFamily(t *testing.T, pid int) {
parent, err := process.NewProcess(int32(pid))

View File

@ -74,7 +74,7 @@ func TestStartStop(t *testing.T) {
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
MaybeParallel(t)
MaybeSlowParallel(t)
if !strings.Contains(tc.name, "docker") && NoneDriver() {
t.Skipf("skipping %s - incompatible with none driver", t.Name())

View File

@ -41,7 +41,7 @@ import (
func TestVersionUpgrade(t *testing.T) {
profile := UniqueProfileName("vupgrade")
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
MaybeParallel(t)
MaybeSlowParallel(t)
defer CleanupWithLogs(t, profile, cancel)