diff --git a/Makefile b/Makefile index ba17066c06..21abb2d0a7 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,8 @@ server: check: fmt lint tidy check-static vet @# Target: run all checkers. (fmt, lint, tidy, check-static and vet) + $(MAKE) -C components/bench ${MAKECMDGOALS} + $(MAKE) -C components/client ${MAKECMDGOALS} check-static: tools/bin/golangci-lint @# Target: run the golangci-lint static check tool @@ -119,6 +121,8 @@ clean: test: failpoint-enable run-tests failpoint-disable @# Target: run tests with failpoint enabled + $(MAKE) -C components/bench ${MAKECMDGOALS} + $(MAKE) -C components/client ${MAKECMDGOALS} # TODO: refactor integration tests base on v1 manifest # run-tests: unit-test integration_test diff --git a/components/bench/ch_benchmark.go b/components/bench/ch_benchmark.go index 127dbdea29..534db84885 100644 --- a/components/bench/ch_benchmark.go +++ b/components/bench/ch_benchmark.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "os" "runtime" "strings" "sync" @@ -32,8 +31,8 @@ func registerCHBenchmark(root *cobra.Command) { var cmdPrepare = &cobra.Command{ Use: "prepare", Short: "Prepare data for the workload", - Run: func(cmd *cobra.Command, args []string) { - executeCH("prepare") + RunE: func(cmd *cobra.Command, args []string) error { + return executeCH("prepare") }, } cmdPrepare.PersistentFlags().BoolVar(&chConfig.CreateTiFlashReplica, @@ -62,21 +61,20 @@ func registerCHBenchmark(root *cobra.Command) { var cmdRun = &cobra.Command{ Use: "run", Short: "Run workload", - Run: func(cmd *cobra.Command, _ []string) { - executeCH("run") + RunE: func(cmd *cobra.Command, _ []string) error { + return executeCH("run") }, } cmd.AddCommand(cmdRun, cmdPrepare) root.AddCommand(cmd) } -func executeCH(action string) { +func executeCH(action string) error { runtime.GOMAXPROCS(maxProcs) if err := openDB(); err != nil { - fmt.Println(err) fmt.Println("Cannot open database, pleae check it (ip/port/username/password)") - os.Exit(1) + return err } defer closeDB() @@ -92,20 +90,16 @@ func executeCH(action string) { ) tp, err = tpcc.NewWorkloader(globalDB, &tpccConfig) if err != nil { - fmt.Printf("Failed to init tp work loader: %v\n", err) - os.Exit(1) + fmt.Println("Failed to init tp work loader") + return err } ap = ch.NewWorkloader(globalDB, &chConfig) - if err != nil { - fmt.Printf("Failed to init tp work loader: %v\n", err) - os.Exit(1) - } timeoutCtx, cancel := context.WithTimeout(globalCtx, totalTime) defer cancel() if action == "prepare" { executeWorkload(timeoutCtx, ap, 1, "prepare") - return + return nil } type workLoaderSetting struct { @@ -125,4 +119,6 @@ func executeCH(action string) { for _, workLoader := range []workLoaderSetting{{workLoader: tp, threads: threads}, {workLoader: ap, threads: acThreads}} { workLoader.workLoader.OutputStats(true) } + + return nil } diff --git a/components/bench/tpcc.go b/components/bench/tpcc.go index 09a25460be..9d99163cc4 100644 --- a/components/bench/tpcc.go +++ b/components/bench/tpcc.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" _ "net/http/pprof" - "os" "runtime" "time" @@ -17,18 +16,18 @@ import ( var tpccConfig tpcc.Config -func executeTpcc(action string) { +func executeTpcc(action string) error { if pprofAddr != "" { go func() { - http.ListenAndServe(pprofAddr, http.DefaultServeMux) + _ = http.ListenAndServe(pprofAddr, http.DefaultServeMux) }() } runtime.GOMAXPROCS(maxProcs) if err := openDB(); err != nil { - fmt.Println(err) fmt.Println("Cannot open database, pleae check it (ip/port/username/password)") - os.Exit(1) + closeDB() + return err } defer closeDB() @@ -42,17 +41,15 @@ func executeTpcc(action string) { switch tpccConfig.OutputType { case "csv", "CSV": if tpccConfig.OutputDir == "" { - fmt.Printf("Output Directory cannot be empty when generating files") - os.Exit(1) + return fmt.Errorf("Output Directory cannot be empty when generating files") } w, err = tpcc.NewCSVWorkloader(globalDB, &tpccConfig) default: w, err = tpcc.NewWorkloader(globalDB, &tpccConfig) } - if err != nil { - fmt.Printf("Failed to init work loader: %v\n", err) - os.Exit(1) + fmt.Println("Failed to init work loader") + return err } timeoutCtx, cancel := context.WithTimeout(globalCtx, totalTime) @@ -62,6 +59,8 @@ func executeTpcc(action string) { fmt.Println("Finished") w.OutputStats(true) + + return nil } func registerTpcc(root *cobra.Command) { @@ -75,8 +74,8 @@ func registerTpcc(root *cobra.Command) { var cmdPrepare = &cobra.Command{ Use: "prepare", Short: "Prepare data for TPCC", - Run: func(cmd *cobra.Command, _ []string) { - executeTpcc("prepare") + RunE: func(cmd *cobra.Command, _ []string) error { + return executeTpcc("prepare") }, } cmdPrepare.PersistentFlags().BoolVar(&tpccConfig.NoCheck, "no-check", false, "TPCC prepare check, default false") @@ -91,8 +90,8 @@ func registerTpcc(root *cobra.Command) { var cmdRun = &cobra.Command{ Use: "run", Short: "Run workload", - Run: func(cmd *cobra.Command, _ []string) { - executeTpcc("run") + RunE: func(cmd *cobra.Command, _ []string) error { + return executeTpcc("run") }, } cmdRun.PersistentFlags().BoolVar(&tpccConfig.Wait, "wait", false, "including keying & thinking time described on TPC-C Standard Specification") @@ -101,16 +100,16 @@ func registerTpcc(root *cobra.Command) { var cmdCleanup = &cobra.Command{ Use: "cleanup", Short: "Cleanup data for the workload", - Run: func(cmd *cobra.Command, _ []string) { - executeTpcc("cleanup") + RunE: func(cmd *cobra.Command, _ []string) error { + return executeTpcc("cleanup") }, } var cmdCheck = &cobra.Command{ Use: "check", Short: "Check data consistency for the workload", - Run: func(cmd *cobra.Command, _ []string) { - executeTpcc("check") + RunE: func(cmd *cobra.Command, _ []string) error { + return executeTpcc("check") }, } diff --git a/components/bench/tpch.go b/components/bench/tpch.go index 29b901bc45..39c26fcadc 100644 --- a/components/bench/tpch.go +++ b/components/bench/tpch.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "os" "strings" "github.com/pingcap/go-tpc/tpch" @@ -12,18 +11,17 @@ import ( var tpchConfig tpch.Config -func executeTpch(action string) { +func executeTpch(action string) error { if err := openDB(); err != nil { - fmt.Println(err) fmt.Println("Cannot open database, pleae check it (ip/port/username/password)") - os.Exit(1) + closeDB() + return err } defer closeDB() // if globalDB == nil if globalDB == nil { - fmt.Fprintln(os.Stderr, "cannot connect to the database") - os.Exit(1) + return fmt.Errorf("cannot connect to the database") } tpchConfig.DBName = dbName @@ -36,6 +34,7 @@ func executeTpch(action string) { executeWorkload(timeoutCtx, w, threads, action) fmt.Println("Finished") w.OutputStats(true) + return nil } func registerTpch(root *cobra.Command) { @@ -66,8 +65,8 @@ func registerTpch(root *cobra.Command) { var cmdPrepare = &cobra.Command{ Use: "prepare", Short: "Prepare data for the workload", - Run: func(cmd *cobra.Command, args []string) { - executeTpch("prepare") + RunE: func(cmd *cobra.Command, args []string) error { + return executeTpch("prepare") }, } @@ -97,16 +96,16 @@ func registerTpch(root *cobra.Command) { var cmdRun = &cobra.Command{ Use: "run", Short: "Run workload", - Run: func(cmd *cobra.Command, args []string) { - executeTpch("run") + RunE: func(cmd *cobra.Command, args []string) error { + return executeTpch("run") }, } var cmdCleanup = &cobra.Command{ Use: "cleanup", Short: "Cleanup data for the workload", - Run: func(cmd *cobra.Command, args []string) { - executeTpch("cleanup") + RunE: func(cmd *cobra.Command, args []string) error { + return executeTpch("cleanup") }, }