forked from PingCAP-QE/clustered-index-rand-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.go
38 lines (33 loc) · 863 Bytes
/
gen.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
package main
import (
"math/rand"
"time"
"github.com/PingCAP-QE/clustered-index-rand-test/sqlgen"
)
type genTestOptions struct {
Grammar string
InitRoot string
TxnRoot string
RecurLimit int
NumTxn int
Debug bool
TiFlash bool
}
func genTest(opts genTestOptions) (test Test, err error) {
rand.Seed(time.Now().UnixNano())
return genTestWithoutGrammarFile(opts)
}
func genTestWithoutGrammarFile(opts genTestOptions) (test Test, err error) {
state := sqlgen.NewState2(opts.TiFlash)
state.InjectTodoSQL("set @@global.tidb_enable_clustered_index=true")
gen := sqlgen.NewGenerator(state)
for i := 0; i < opts.NumTxn; i++ {
txnStmtCount := 1 + rand.Intn(200)
txn := make(Txn, 0, txnStmtCount)
for j := 0; j < txnStmtCount; j++ {
txn = append(txn, Stmt{Stmt: gen()})
}
test.Steps = append(test.Steps, txn)
}
return
}