From 1284eb47427824e6c5adaa712c3a3ffcc10c5412 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 13 Jun 2024 21:06:57 +0530 Subject: [PATCH] feat: add a flag to control the test directory of vitess-tester Signed-off-by: Manan Gupta --- README.md | 52 ++++++++++++++++++++++++++++++------- main.go | 8 +++--- src/vitess-tester/tester.go | 6 +++-- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 28069d5..e0ecf61 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,6 @@ A critical aspect of working with Vitess involves defining sharding keys for all This method allows us to thoroughly test queries within a sharded environment, ensuring that applications running on Vitess can confidently handle both uniform and edge-case scenarios. By prioritizing functional correctness over performance in our testing environment, we can guarantee that Vitess behaves as expected under a variety of sharding configurations. -## Requirements - -- All the tests should be put in [`t`](./t), take [t/example.test](./t/example.test) as an example. - ## How to use Build the `vitess-tester` binary: @@ -41,14 +37,52 @@ make Basic usage: ``` Usage of ./vitess-tester: - --log-level string + -alsologtostderr + log to standard error as well as files + -force-base-tablet-uid int + force assigning tablet ports based on this seed + -force-port-start int + force assigning ports based on this seed + -force-vtdataroot string + force path for VTDATAROOT, which may already be populated + -is-coverage + whether coverage is required + -keep-data + don't delete the per-test VTDATAROOT subfolders (default true) + -log-level string The log level of vitess-tester: info, warn, error, debug. (default "error") - --olap + -log_backtrace_at value + when logging hits line file:N, emit a stack trace + -log_dir string + If non-empty, write log files in this directory + -log_link string + If non-empty, add symbolic links in this directory to the log files + -logbuflevel int + Buffer log messages logged at this level or lower (-1 means don't buffer; 0 means buffer INFO only; ...). Has limited applicability on non-prod platforms. + -logtostderr + log to standard error instead of files + -olap Use OLAP to run the queries. - --sharded + -partial-keyspace + add a second keyspace for sharded tests and mark first shard as moved to this keyspace in the shard routing rules + -perf-test + include end-to-end performance tests + -sharded run all tests on a sharded keyspace - --vschema file-name - The vschema file to use for sharded tests. + -stderrthreshold value + logs at or above this threshold go to stderr (default 2) + -test-dir string + Directory for the test files (default "./t/") + -topo-flavor string + choose a topo server from etcd2, zk2 or consul (default "etcd2") + -v value + log level for V logs + -vmodule value + comma-separated list of pattern=N settings for file-filtered logging + -vschema string + Disable auto-vschema by providing your own vschema file + -xunit + Get output in an xml file instead of errors directory ``` By default, it connects to the MySQL server at 127.0.0.1 with root and no password, and to the vtgate server at 127.0.0.1 with root and no password: diff --git a/main.go b/main.go index d1a14ff..1fc2311 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ var ( olap bool vschemaFile string xunit bool + testDir string ) func init() { @@ -45,17 +46,18 @@ func init() { flag.BoolVar(&sharded, "sharded", false, "run all tests on a sharded keyspace") flag.StringVar(&vschemaFile, "vschema", "", "Disable auto-vschema by providing your own vschema file") flag.BoolVar(&xunit, "xunit", false, "Get output in an xml file instead of errors directory") + flag.StringVar(&testDir, "test-dir", "./t/", "Directory for the test files") } func loadAllTests() (tests []string, err error) { // tests must be in t folder or subdir in t folder - err = filepath.Walk("./t/", func(path string, info os.FileInfo, err error) error { + err = filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() && strings.HasSuffix(path, ".test") { - name := strings.TrimPrefix(strings.TrimSuffix(path, ".test"), "t/") + name := strings.TrimSuffix(info.Name(), ".test") tests = append(tests, name) } return nil @@ -70,7 +72,7 @@ func loadAllTests() (tests []string, err error) { func executeTests(clusterInstance *cluster.LocalProcessCluster, vtParams, mysqlParams mysql.ConnParams, fileNames []string, s vitess_tester.Suite) (failed bool) { for _, name := range fileNames { errReporter := s.NewReporterForFile(name) - vTester := vitess_tester.NewTester(name, errReporter, clusterInstance, vtParams, mysqlParams, olap, keyspaceName, vschema, vschemaFile) + vTester := vitess_tester.NewTester(name, errReporter, clusterInstance, vtParams, mysqlParams, olap, keyspaceName, vschema, testDir, vschemaFile) err := vTester.Run() if err != nil { failed = true diff --git a/src/vitess-tester/tester.go b/src/vitess-tester/tester.go index 640e8f2..af0e048 100644 --- a/src/vitess-tester/tester.go +++ b/src/vitess-tester/tester.go @@ -36,6 +36,7 @@ import ( ) type tester struct { + dir string name string clusterInstance *cluster.LocalProcessCluster @@ -65,6 +66,7 @@ func NewTester(name string, reporter Reporter, olap bool, keyspaceName string, vschema vindexes.VSchema, + dir string, vschemaFile string, ) *tester { t := &tester{ @@ -76,6 +78,7 @@ func NewTester(name string, reporter Reporter, keyspaceName: keyspaceName, vschema: vschema, vschemaFile: vschemaFile, + dir: dir, olap: olap, } return t @@ -386,8 +389,7 @@ func (t *tester) handleCreateTable(create *sqlparser.CreateTable) { } func (t *tester) testFileName() string { - // test and result must be in current ./t the same as MySQL - return fmt.Sprintf("./t/%s.test", t.name) + return fmt.Sprintf("%s/%s.test", t.dir, t.name) } func (t *tester) Errorf(format string, args ...interface{}) {