github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+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 ) 14 15 var _ = Describe("services command performance", func() { 16 const ( 17 serviceName = "service" 18 servicePlan = "service-plan" 19 ) 20 21 var ( 22 broker helpers.ServiceBroker 23 currentExecution int 24 maxExecutions = getEnvOrDefault("MAX_EXECUTIONS", 10) 25 numberOfServices = getEnvOrDefault("NUMBER_OF_SERVICE_INSTANCES", 15) 26 ) 27 28 BeforeEach(func() { 29 helpers.LoginCF() 30 helpers.TargetOrgAndSpace(perfOrg, perfSpace) 31 32 currentExecution++ 33 if os.Getenv("SKIP_PERF_SETUP") == "true" || currentExecution > 1 { 34 return 35 } 36 37 /* Display some useful information */ 38 fmt.Printf("Number of samples (MAX_EXECUTIONS): %d\n", maxExecutions) 39 fmt.Printf("Number of service instances (NUMBER_OF_SERVICE_INSTANCES): %d\n", numberOfServices) 40 41 domain := helpers.DefaultSharedDomain() 42 broker = helpers.CreateBroker(domain, serviceName, servicePlan) 43 44 Eventually(helpers.CF("enable-service-access", serviceName)).Should(Exit(0)) 45 46 for i := 0; i < numberOfServices; i++ { 47 Eventually(helpers.CF("create-service", serviceName, servicePlan, fmt.Sprintf("instance-%d", i))).Should(Exit(0)) 48 } 49 }) 50 51 AfterEach(func() { 52 if currentExecution == maxExecutions { 53 for i := 0; i < numberOfServices; i++ { 54 Eventually(helpers.CF("delete-service", fmt.Sprintf("instance-%d", i), "-f")).Should(Exit(0)) 55 } 56 broker.Destroy() 57 } 58 }) 59 60 Measure("services command", func(b Benchmarker) { 61 b.Time("cf services", func() { 62 fmt.Printf("cf services...") 63 session := helpers.CF("services") 64 session.Wait() 65 fmt.Printf(" DONE.\n") 66 Expect(session).Should(Exit(0)) 67 }) 68 }, maxExecutions) 69 }) 70 71 func getEnvOrDefault(key string, defaultValue int) int { 72 val, ok := os.LookupEnv(key) 73 if !ok { 74 return defaultValue 75 } 76 77 value, err := strconv.Atoi(val) 78 if err == nil { 79 return value 80 } 81 return defaultValue 82 }