You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch adds a convenient and canonical API for runtime assertions,
inspired by the Testify package used for Go test assertions. It is
intended to encourage liberal use of runtime assertions throughout the
code base, by making it as easy as possible to write assertions that
follow best practices. It does not attempt to reinvent the wheel, but
instead builds on existing infrastructure.
Assertion failures are fatal in all non-release builds, including
roachprod clusters and roachtests, to ensure they will be noticed. In
release builds, they instead log the failure and report it to Sentry (if
enabled), and return an assertion error to the caller for propagation.
This avoids excessive disruption in production environments, where an
assertion failure is often scoped to an individual RPC request,
transaction, or range, and crashing the node can turn a minor problem
into a full-blown outage. It is still possible to kill the node when
appropriate via `log.Fatalf`, but this should be the exception rather
than the norm.
It also supports expensive assertions that must be compiled out of
normal dev/test/release builds for performance reasons. These are
instead enabled in special test builds.
This is intended to be used instead of other existing assertion
mechanisms, which have various shortcomings:
* `log.Fatalf`: kills the node even in release builds, which can cause
severe disruption over often minor issues.
* `errors.AssertionFailedf`: only suitable when we have an error return
path, does not fatal in non-release builds, and are not always
notified in release builds.
* `logcrash.ReportOrPanic`: panics rather than fatals, which can leave
the node limping along. Requires the caller to implement separate
assertion handling in release builds, which is easy to forget. Also
requires propagating cluster settings, which aren't always available.
* `buildutil.CrdbTestBuild`: only enabled in Go tests, not roachtests,
roachprod clusters, or production clusters.
* `util.RaceEnabled`: only enabled in race builds. Expensive assertions
should be possible to run without the additional overhead of the race
detector.
For more details and examples, see the `must` package documentation.
Epic: none
Release note: None
0 commit comments