From 0fd4f17c0acbca4d48d331f09e5a29ae0b6dc7fa Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 23 Jun 2020 09:10:56 -0700 Subject: [PATCH 1/4] Automatically limit integration test parallelism --- test/integration/{main.go => main_test.go} | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) rename test/integration/{main.go => main_test.go} (79%) diff --git a/test/integration/main.go b/test/integration/main_test.go similarity index 79% rename from test/integration/main.go rename to test/integration/main_test.go index 170bf02acc11..c1eb1469f7d1 100644 --- a/test/integration/main.go +++ b/test/integration/main_test.go @@ -19,8 +19,10 @@ package integration import ( "flag" "fmt" + "math" "os" "runtime" + "strconv" "strings" "testing" "time" @@ -51,12 +53,43 @@ const ( // TestMain is the test main func TestMain(m *testing.M) { flag.Parse() + setMaxParallelism() + start := time.Now() code := m.Run() fmt.Printf("Tests completed in %s (result code %d)\n", time.Since(start), code) os.Exit(code) } +// setMaxParallelism caps the max parallelism. Go assumes 1 core per test, whereas minikube needs 2 cores per test. +func setMaxParallelism() { + procs := runtime.GOMAXPROCS(0) + pval := flag.Lookup("test.parallel").Value.String() + pv, err := strconv.Atoi(pval) + if err != nil { + fmt.Fprintf(os.Stderr, "unable to parse --test.parallel value: %q\n", pval) + return + } + + if procs != pv { + fmt.Fprintf(os.Stderr, "--test-parallel=%d was set via flags (system has %d cores)\n", pv, procs) + return + } + + if procs == 2 { + fmt.Fprintf(os.Stderr, "Found %d cores, will not round down core count.\n", procs) + return + } + + // During "minikube start", minikube briefly consumes ~1.5 cores. Most of the time it's less. + limit := int(math.Floor(float64(procs) * 0.75)) + fmt.Fprintf(os.Stderr, "Found %d cores, limiting parallelism with --test.parallel=%d\n", procs, limit) + if err := flag.Set("test.parallel", strconv.Itoa(limit)); err != nil { + fmt.Fprintf(os.Stderr, "Unable to set test.parallel: %v\n", err) + } + runtime.GOMAXPROCS(limit) +} + // StartArgs returns the arguments normally used for starting minikube func StartArgs() []string { return strings.Split(*startArgs, " ") From 3659fd5203df5db79d7ec7a87991d5b9e5541396 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 23 Jun 2020 09:16:29 -0700 Subject: [PATCH 2/4] Use 0.6 CPU count by default --- test/integration/main_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/main_test.go b/test/integration/main_test.go index c1eb1469f7d1..3514ef1bf601 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -81,8 +81,8 @@ func setMaxParallelism() { return } - // During "minikube start", minikube briefly consumes ~1.5 cores. Most of the time it's less. - limit := int(math.Floor(float64(procs) * 0.75)) + // Each "minikube start" consumes up to 2 cores - during startup, ~1.5 cores is typical + limit := int(math.Floor(float64(procs) * 0.6)) fmt.Fprintf(os.Stderr, "Found %d cores, limiting parallelism with --test.parallel=%d\n", procs, limit) if err := flag.Set("test.parallel", strconv.Itoa(limit)); err != nil { fmt.Fprintf(os.Stderr, "Unable to set test.parallel: %v\n", err) From c5f59b1eded421de2c79abdc549ead514a1d574e Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 23 Jun 2020 09:51:08 -0700 Subject: [PATCH 3/4] Make the calculation easier to understand --- test/integration/main_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 3514ef1bf601..fb9040d14990 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -81,8 +81,9 @@ func setMaxParallelism() { return } - // Each "minikube start" consumes up to 2 cores - during startup, ~1.5 cores is typical - limit := int(math.Floor(float64(procs) * 0.6)) + // Each "minikube start" consumes up to 2 cores, though the average usage is somewhat lower + limit := int(math.Floor(float64(procs) / 1.75)) + fmt.Fprintf(os.Stderr, "Found %d cores, limiting parallelism with --test.parallel=%d\n", procs, limit) if err := flag.Set("test.parallel", strconv.Itoa(limit)); err != nil { fmt.Fprintf(os.Stderr, "Unable to set test.parallel: %v\n", err) From 25001d771518f053be90ccdb50087e0915f72784 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 23 Jun 2020 10:03:58 -0700 Subject: [PATCH 4/4] Add _test.go suffix everywhere to avoid symbol resolution issues --- .../{fn_mount_cmd.go => fn_mount_cmd_test.go} | 0 .../integration/{fn_pvc.go => fn_pvc_test.go} | 0 ...fn_tunnel_cmd.go => fn_tunnel_cmd_test.go} | 0 .../{helpers.go => helpers_test.go} | 0 test/integration/main_test.go | 23 +++++++++++-------- test/integration/{util.go => util_test.go} | 0 6 files changed, 13 insertions(+), 10 deletions(-) rename test/integration/{fn_mount_cmd.go => fn_mount_cmd_test.go} (100%) rename test/integration/{fn_pvc.go => fn_pvc_test.go} (100%) rename test/integration/{fn_tunnel_cmd.go => fn_tunnel_cmd_test.go} (100%) rename test/integration/{helpers.go => helpers_test.go} (100%) rename test/integration/{util.go => util_test.go} (100%) diff --git a/test/integration/fn_mount_cmd.go b/test/integration/fn_mount_cmd_test.go similarity index 100% rename from test/integration/fn_mount_cmd.go rename to test/integration/fn_mount_cmd_test.go diff --git a/test/integration/fn_pvc.go b/test/integration/fn_pvc_test.go similarity index 100% rename from test/integration/fn_pvc.go rename to test/integration/fn_pvc_test.go diff --git a/test/integration/fn_tunnel_cmd.go b/test/integration/fn_tunnel_cmd_test.go similarity index 100% rename from test/integration/fn_tunnel_cmd.go rename to test/integration/fn_tunnel_cmd_test.go diff --git a/test/integration/helpers.go b/test/integration/helpers_test.go similarity index 100% rename from test/integration/helpers.go rename to test/integration/helpers_test.go diff --git a/test/integration/main_test.go b/test/integration/main_test.go index fb9040d14990..3359aeb26119 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -63,28 +63,31 @@ func TestMain(m *testing.M) { // setMaxParallelism caps the max parallelism. Go assumes 1 core per test, whereas minikube needs 2 cores per test. func setMaxParallelism() { - procs := runtime.GOMAXPROCS(0) - pval := flag.Lookup("test.parallel").Value.String() - pv, err := strconv.Atoi(pval) + + flagVal := flag.Lookup("test.parallel").Value.String() + requested, err := strconv.Atoi(flagVal) if err != nil { - fmt.Fprintf(os.Stderr, "unable to parse --test.parallel value: %q\n", pval) + fmt.Fprintf(os.Stderr, "unable to parse --test.parallel value: %q\n", flagVal) return } - if procs != pv { - fmt.Fprintf(os.Stderr, "--test-parallel=%d was set via flags (system has %d cores)\n", pv, procs) + maxp := runtime.GOMAXPROCS(0) + + // Do not ignore what the user has explicitly set + if requested != maxp { + fmt.Fprintf(os.Stderr, "--test-parallel=%d was set via flags (system has %d cores)\n", requested, maxp) return } - if procs == 2 { - fmt.Fprintf(os.Stderr, "Found %d cores, will not round down core count.\n", procs) + if maxp == 2 { + fmt.Fprintf(os.Stderr, "Found %d cores, will not round down core count.\n", maxp) return } // Each "minikube start" consumes up to 2 cores, though the average usage is somewhat lower - limit := int(math.Floor(float64(procs) / 1.75)) + limit := int(math.Floor(float64(maxp) / 1.75)) - fmt.Fprintf(os.Stderr, "Found %d cores, limiting parallelism with --test.parallel=%d\n", procs, limit) + fmt.Fprintf(os.Stderr, "Found %d cores, limiting parallelism with --test.parallel=%d\n", maxp, limit) if err := flag.Set("test.parallel", strconv.Itoa(limit)); err != nil { fmt.Fprintf(os.Stderr, "Unable to set test.parallel: %v\n", err) } diff --git a/test/integration/util.go b/test/integration/util_test.go similarity index 100% rename from test/integration/util.go rename to test/integration/util_test.go