Skip to content

Commit

Permalink
Merge pull request #8537 from tstromberg/limit-parallel
Browse files Browse the repository at this point in the history
Automatically limit integration test parallelism
  • Loading branch information
tstromberg authored Jun 23, 2020
2 parents 756df19 + 25001d7 commit b1c26a2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions test/integration/main.go → test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package integration
import (
"flag"
"fmt"
"math"
"os"
"runtime"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -51,12 +53,47 @@ 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() {

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", flagVal)
return
}

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 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(maxp) / 1.75))

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)
}
runtime.GOMAXPROCS(limit)
}

// StartArgs returns the arguments normally used for starting minikube
func StartArgs() []string {
return strings.Split(*startArgs, " ")
Expand Down
File renamed without changes.

0 comments on commit b1c26a2

Please sign in to comment.