diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index ade8cc9ff8..f363de6ef3 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -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) diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go index 629033ca5b..52970ea6b7 100644 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -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) diff --git a/test/integration/guest_env_test.go b/test/integration/guest_env_test.go index f5b3593669..e9f4925a27 100644 --- a/test/integration/guest_env_test.go +++ b/test/integration/guest_env_test.go @@ -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) diff --git a/test/integration/gvisor_addon_test.go b/test/integration/gvisor_addon_test.go index b54a148d0d..e801aef446 100644 --- a/test/integration/gvisor_addon_test.go +++ b/test/integration/gvisor_addon_test.go @@ -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) diff --git a/test/integration/helpers.go b/test/integration/helpers.go index 49cd0a0f08..7c3688bac3 100644 --- a/test/integration/helpers.go +++ b/test/integration/helpers.go @@ -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)) diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 9e6fc0fd21..bf575baeee 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -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()) diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 9296bdde94..09de47d331 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -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)