Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
45563: logictest: add a kvtrace test type to logic tests. r=jordanlewis a=jordanlewis

It's common to want to test "kv trace" output in execbuilder tests, to
make sure that a particular SQL statement emits the expected set of key
reads, writes, deletes, and so on. It's very annoying to re-type out the
setup for kv tracing every time (it's multiple boiler plate-y lines), so
this commit introduces a shortcut for this common operation.

It looks like this:

```
query T kvtrace
SELECT * FROM t
----
<expected kv trace output>
```

Release note: None

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Mar 2, 2020
2 parents e2bfd6b + 7f6afc1 commit 860c137
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ type logicQuery struct {
// expectedHash is set.
expectedValues int

// kvtrace indicates that we're comparing the output of a kv trace.
kvtrace bool

// rawOpts are the query options, before parsing. Used to display in error
// messages.
rawOpts string
Expand Down Expand Up @@ -1574,6 +1577,9 @@ func (t *logicTest) processSubtest(
case "retry":
query.retry = true

case "kvtrace":
query.kvtrace = true

default:
return errors.Errorf("%s: unknown sort mode: %s", query.pos, opt)
}
Expand Down Expand Up @@ -1658,6 +1664,32 @@ func (t *logicTest) processSubtest(
}

if !s.skip {
if query.kvtrace {
_, err := t.db.Exec("SET TRACING=on,kv")
if err != nil {
return err
}
_, err = t.db.Exec(query.sql)
if err != nil {
t.Error(err)
}
_, err = t.db.Exec("SET TRACING=off")
if err != nil {
return err
}
query.colTypes = "T"
query.sql = `SELECT message FROM [SHOW KV TRACE FOR SESSION]
WHERE message LIKE 'CPut%'
OR message LIKE 'Put%'
OR message LIKE 'InitPut%'
OR message LIKE 'Del%'
OR message LIKE 'ClearRange%'
OR message LIKE 'Get%'
OR message LIKE 'Scan%'
OR message LIKE 'FKScan%'
OR message LIKE 'CascadeScan%'`
}

for i := 0; i < repeat; i++ {
if query.retry && !*rewriteResultsInTestfiles {
testutils.SucceedsSoon(t.rootT, func() error {
Expand Down

0 comments on commit 860c137

Please sign in to comment.