-
Notifications
You must be signed in to change notification settings - Fork 32
Description
The goal of this issue is to easily enable custom invariant checking for StrictTVar
s etc. that are always tested on CI (and not just nightly CI).
Status quo
We use the strict-checked-vars
library to get variants of StrictTVar
s/StrictMVar
s which allow one to check invariants every time their value is updated. This library provides two flags, checktvarinvariants
and checkmvarinvariants
(disabled by default), which one needs to enable to actually get invariant-checking behavior.
- When building for production (in
cardano-node
), these flags are disabled, causing no runtime overhead. - When building for our nightly nothunks tests, we enable them
flags: +checktvarinvariants +checkmvarinvariants
By default, the invariant we check is the nothunks
property; also see the description of this module. Sometimes, we additionally have domain-specific invariants using newTVarWithInvariant
/newMVarWithInvariant
.
Notably, in regular CI, we don't actually enable these invariants at all, because the nothunks
checks are way too expensive for the regular CI. However, the domain-specific invariants would be nice to check even in regular CI (especially as we are neglecting our nightly CI...)
Desired change
It is suboptimal that we can't have invariants for eg TVar
s which are checked in regular CI, as well as when running tests locally. Therefore, the goal is to gate the nothunks
checks behind an additional flag (say expensive-invariants
), which is only enabled on nightly CI, and to then enable checktvarinvariants
and checkmvarinvariants
even on regular CI.
There are also one more place where we call checkInvariant
with nothunks
checks apart from the TVar
s/MVar
s; this should also be gated behind the new expensive-invariants
flag:
Lines 2192 to 2193 in 698f67e
continueWithState !s (Stateful f) = | |
checkInvariant (show <$> unsafeNoThunks s) $ f s |
(#1615 will add something similar)
This will result in the following setup:
- In production: No invariant checking at all
- In regular CI: Cheap invariant checking (domain-specific invariants)
- In nightly CI: Cheap and expensive invariant checking
Motivated by #1615 (comment)