Skip to content

Commit

Permalink
roachtest: remove interesting whitespace characters in random SQL tes…
Browse files Browse the repository at this point in the history
…ts logs

In cockroachdb#102038 we started writing statements to the query log in SQL
comments. The change removes newline characters in the statement to
ensure that the statement will be on one line all within the comment.
However, we still see test logs where the comments are broken onto
multiple lines, as in cockroachdb#118273, which makes the file invalid
syntactically. This makes reproducing the test failure more difficult
because the comments have to be manually fixed so that the log file can
be successfully parsed.

I was able to determine that the line breaks are coming from other
"interesting" whitespace characters. The `xxd` output from the log file
in cockroachdb#118273 shows the carriage return character, `0d` being used in the
middle of a column name:

    00000090: 2041 5320 2263 6f0d 6c33 3830 2246 524f   AS "co.l380"FRO

This commit strips all interesting whitespace characters from the
statement to prevent the comment from being broken on multiple lines.

Release note: None
  • Loading branch information
mgartner committed Jan 25, 2024
1 parent dc7c41a commit 273db8f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/cmd/roachtest/tests/query_comparison_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ type queryComparisonHelper struct {
colTypes []string
}

// stmtReplacer removes interesting white space characters that may be in
// a column or table name. See nameGenerator.GenerateOne.
var stmtReplacer = strings.NewReplacer("\n", "", "\r", "", "\f", "", "\v", "")

// runQuery runs the given query and returns the output. If the stmt doesn't
// result in an error, as a side effect, it also saves the query, the query
// plan, and the output of running the query so they can be logged in case of
Expand All @@ -450,7 +454,7 @@ func (h *queryComparisonHelper) runQuery(stmt string) ([][]string, error) {
// Remove all newline symbols to log this stmt as a single line. This
// way this auxiliary logging takes up less space (if the stmt executes
// successfully, it'll still get logged with the nice formatting).
strings.ReplaceAll(stmt, "\n", "")),
stmtReplacer.Replace(stmt)),
)

runQueryImpl := func(stmt string) ([][]string, error) {
Expand Down

0 comments on commit 273db8f

Please sign in to comment.