Skip to content

Commit

Permalink
feat: add a flag to control the test directory of vitess-tester
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Jun 13, 2024
1 parent 6d3b4f0 commit 1284eb4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
olap bool
vschemaFile string
xunit bool
testDir string
)

func init() {
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/vitess-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

type tester struct {
dir string
name string

clusterInstance *cluster.LocalProcessCluster
Expand Down Expand Up @@ -65,6 +66,7 @@ func NewTester(name string, reporter Reporter,
olap bool,
keyspaceName string,
vschema vindexes.VSchema,
dir string,
vschemaFile string,
) *tester {
t := &tester{
Expand All @@ -76,6 +78,7 @@ func NewTester(name string, reporter Reporter,
keyspaceName: keyspaceName,
vschema: vschema,
vschemaFile: vschemaFile,
dir: dir,
olap: olap,
}
return t
Expand Down Expand Up @@ -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{}) {
Expand Down

0 comments on commit 1284eb4

Please sign in to comment.