Skip to content

Commit

Permalink
logictest: add a kvtrace test type to logic tests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jordanlewis committed Mar 1, 2020
1 parent 14094e3 commit 7f6afc1
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 7f6afc1

Please sign in to comment.