Skip to content

Commit

Permalink
roachtest/costfuzz: create failure.log file on demand
Browse files Browse the repository at this point in the history
This commit makes it so that `failure.log` files are created lazily on
demand in `costfuzz` and `unoptimized_query_oracle` roachtests. It seems
nicer this way since for successful runs previously we'd see empty
failure log files which were a bit confusing.

Epic: None

Release note: None
  • Loading branch information
yuzefovich committed Aug 15, 2023
1 parent dc2c52d commit 0eab110
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/cmd/roachtest/tests/query_comparison_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,23 @@ func runOneRoundQueryComparison(
t.L().Printf("\n\n")
}

failureLogPath := filepath.Join(
t.ArtifactsDir(), fmt.Sprintf("%s%03d.failure.log", qct.name, iter),
)
failureLog, err := os.Create(failureLogPath)
if err != nil {
t.Fatalf("could not create %s%03d.failure.log: %v", qct.name, iter, err)
}
defer failureLog.Close()
// We will create the failure log file on demand.
var failureLog *os.File
defer func() {
if failureLog != nil {
_ = failureLog.Close()
}
}()
logFailure := func(stmt string, rows [][]string) {
if failureLog == nil {
failureLogName := fmt.Sprintf("%s%03d.failure.log", qct.name, iter)
failureLogPath := filepath.Join(t.ArtifactsDir(), failureLogName)
var err error
failureLog, err = os.Create(failureLogPath)
if err != nil {
t.Fatalf("could not create %s: %v", failureLogName, err)
}
}
fmt.Fprint(failureLog, stmt)
fmt.Fprint(failureLog, "\n----\n")
fmt.Fprint(failureLog, sqlutils.MatrixToStr(rows))
Expand Down

0 comments on commit 0eab110

Please sign in to comment.