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 #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 #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 #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 a83d152 commit 5532dbf
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/cmd/roachtest/tests/query_comparison_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strings"
"time"
"unicode"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
Expand Down Expand Up @@ -313,11 +314,17 @@ func (h *queryComparisonHelper) runQuery(stmt string) ([][]string, error) {
// such a scenario, since the stmt didn't execute successfully, it won't get
// logged by the caller).
h.logStmt(fmt.Sprintf("-- %s: %s", timeutil.Now(),
// 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", "")),
)
// Remove all control characters, including 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.Map(func(r rune) rune {
if unicode.IsControl(r) {
return -1
}
return r
}, stmt),
))

runQueryImpl := func(stmt string) ([][]string, error) {
rows, err := h.conn.Query(stmt)
Expand Down

0 comments on commit 5532dbf

Please sign in to comment.