-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (83 loc) · 2.25 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"github.com/you06/doppelganger/core"
"github.com/you06/doppelganger/executor"
"github.com/you06/doppelganger/util"
"github.com/juju/errors"
"github.com/ngaut/log"
_ "github.com/pingcap/tidb/types/parser_driver"
)
var (
printVersion bool
dsn1 string
dsn2 string
printSchema bool
clearDB bool
logPath string
reproduce string
stable bool
concurrency int
)
func init() {
flag.BoolVar(&printVersion, "V", false, "print version")
flag.BoolVar(&printSchema, "schema", false, "print schema and exit")
flag.StringVar(&dsn1, "dsn1", "", "dsn1")
flag.StringVar(&dsn2, "dsn2", "", "dsn2")
flag.BoolVar(&clearDB, "clear", false, "drop all tables in target database and then start testing")
flag.StringVar(&logPath, "log", "", "log path")
flag.StringVar(&reproduce, "re", "", "reproduce from logs, dir:table, will execute only the given table unless all table")
flag.BoolVar(&stable, "stable", false, "generate stable SQL without random or other env related expression")
flag.IntVar(&concurrency, "concurrency", 1, "test concurrency")
}
func main() {
flag.Parse()
if printVersion {
util.PrintInfo()
os.Exit(0)
}
var (
exec *core.Executor
err error
executorOption = executor.Option{}
coreOption = core.Option{}
)
executorOption.Clear = clearDB
executorOption.Log = logPath
executorOption.Reproduce = reproduce
executorOption.Stable = stable
coreOption.Stable = stable
coreOption.Concurrency = concurrency
coreOption.Reproduce = reproduce
if dsn1 == "" {
log.Fatalf("dsn1 can not be empty")
} else if dsn2 == "" {
exec, err = core.New(dsn1, &coreOption, &executorOption)
} else {
exec, err = core.NewABTest(dsn1, dsn2, &coreOption, &executorOption)
}
if err != nil {
log.Fatalf("create executor error %v", errors.ErrorStack(err))
}
if printSchema {
if err := exec.PrintSchema(); err != nil {
log.Fatalf("print schema err %v", errors.ErrorStack(err))
}
os.Exit(0)
}
if err := exec.Start(); err != nil {
log.Fatalf("start exec error %v", err)
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
os.Kill,
os.Interrupt,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
log.Infof("Got signal %d to exit.", <-sc)
}