github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/shared/performance/services_command_performance_test.go (about)

     1  package performance_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gexec"
    11  
    12  	"code.cloudfoundry.org/cli/integration/helpers"
    13  	"code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker"
    14  )
    15  
    16  var _ = Describe("services command performance", func() {
    17  	var (
    18  		broker           *fakeservicebroker.FakeServiceBroker
    19  		currentExecution int
    20  		maxExecutions    = getEnvOrDefault("MAX_EXECUTIONS", 10)
    21  		numberOfServices = getEnvOrDefault("NUMBER_OF_SERVICE_INSTANCES", 15)
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		helpers.LoginCF()
    26  		helpers.TargetOrgAndSpace(perfOrg, perfSpace)
    27  
    28  		currentExecution++
    29  		if os.Getenv("SKIP_PERF_SETUP") == "true" || currentExecution > 1 {
    30  			return
    31  		}
    32  
    33  		/* Display some useful information */
    34  		fmt.Printf("Number of samples (MAX_EXECUTIONS): %d\n", maxExecutions)
    35  		fmt.Printf("Number of service instances (NUMBER_OF_SERVICE_INSTANCES): %d\n", numberOfServices)
    36  
    37  		broker = fakeservicebroker.New().EnsureBrokerIsAvailable()
    38  
    39  		Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0))
    40  
    41  		for i := 0; i < numberOfServices; i++ {
    42  			Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), fmt.Sprintf("instance-%d", i))).Should(Exit(0))
    43  		}
    44  	})
    45  
    46  	AfterEach(func() {
    47  		if currentExecution == maxExecutions {
    48  			for i := 0; i < numberOfServices; i++ {
    49  				Eventually(helpers.CF("delete-service", fmt.Sprintf("instance-%d", i), "-f")).Should(Exit(0))
    50  			}
    51  			broker.Destroy()
    52  		}
    53  	})
    54  
    55  	Measure("services command", func(b Benchmarker) {
    56  		b.Time("cf services", func() {
    57  			fmt.Printf("cf services...")
    58  			session := helpers.CF("services")
    59  			session.Wait()
    60  			fmt.Printf(" DONE.\n")
    61  			Expect(session).Should(Exit(0))
    62  		})
    63  	}, maxExecutions)
    64  })
    65  
    66  func getEnvOrDefault(key string, defaultValue int) int {
    67  	val, ok := os.LookupEnv(key)
    68  	if !ok {
    69  		return defaultValue
    70  	}
    71  
    72  	value, err := strconv.Atoi(val)
    73  	if err == nil {
    74  		return value
    75  	}
    76  	return defaultValue
    77  }