Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests for go submodules #1579

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions components/bench/ch_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand All @@ -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 {
Expand All @@ -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
}
35 changes: 17 additions & 18 deletions components/bench/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"time"

Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -62,6 +59,8 @@ func executeTpcc(action string) {

fmt.Println("Finished")
w.OutputStats(true)

return nil
}

func registerTpcc(root *cobra.Command) {
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
},
}

Expand Down
23 changes: 11 additions & 12 deletions components/bench/tpch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"os"
"strings"

"github.com/pingcap/go-tpc/tpch"
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
},
}

Expand Down Expand Up @@ -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")
},
}

Expand Down