Skip to content

Commit

Permalink
meta: fail execution if Fatalf was used
Browse files Browse the repository at this point in the history
`Fatalf` was storing an error but we were never checking it. It will
now fail the execution.
  • Loading branch information
RaduBerinde committed Apr 26, 2024
1 parent 1b234bd commit ef5c430
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions metamorphic/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ func (h *history) Fatalf(format string, args ...interface{}) {
panic(fmt.Sprintf(format, args...))
}
_ = h.log.Output(2, h.format("FATAL", format, args...))
h.err.Store(errors.Errorf(format, args...))
// Store the first fatal error message.
h.err.CompareAndSwap(nil, errors.Errorf(format, args...))
}

func (h *history) recorder(
Expand Down Expand Up @@ -206,7 +207,11 @@ func reorderHistory(lines []string) []string {
if cleaned := strings.TrimSpace(l); cleaned == "" {
continue
}
reordered[extractOp(l)] = l
idx := extractOp(l)
if idx >= len(reordered) {
panic("incomplete test history; this shouldn't happen given that execution completed successfully")
}
reordered[idx] = l
}
return reordered
}
Expand Down
4 changes: 3 additions & 1 deletion metamorphic/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"testing"
"time"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/dsl"
"github.com/cockroachdb/pebble/internal/randvar"
"github.com/cockroachdb/pebble/vfs"
"github.com/cockroachdb/pebble/vfs/errorfs"
"github.com/pkg/errors"
"github.com/pmezard/go-difflib/difflib"
"github.com/stretchr/testify/require"
"golang.org/x/exp/rand"
Expand Down Expand Up @@ -572,6 +572,8 @@ func RunOnce(t TestingT, runDir string, seed uint64, historyPath string, rOpts .
fmt.Fprintf(os.Stderr, "\n%s\n", db.LSMViewURL())
}
}
// Don't let the test pass if it issued a Fatalf.
err = errors.CombineErrors(err, h.Error())

if err != nil {
m.saveInMemoryData()
Expand Down

0 comments on commit ef5c430

Please sign in to comment.