htlcswitch: fail fast when hodl tests run without the dev tag #11623
LGTM. I verified the thing that matters for this change — that the sweep is actually complete — and it is.
I enumerated every test in htlcswitch that touches a hodl mask or hodl flags on your head (72fe529474):
TestChannelLinkBandwidthConsistency — HodlMask at 2514, guardedTestChannelLinkTrimCircuitsNoCommit — HodlMask at 3294 plus hodl.Commit passed through alice.restart(...) at 3372/3406/3474, guardedTestChannelLinkCleanupSpuriousResponses — HodlMask at 5538, guardedTestPipelineSettle — HodlMask at 7579, guardedTestSwitchDustForwarding — guardedThe only other HodlMask assignment is at 4963 inside persistentLinkHarness.restartLink, which is a helper taking hodlFlags []hodl.Flag; the only call site that passes real flags (4795) is reached from TestChannelLinkTrimCircuitsNoCommit, which is guarded. So no unguarded test in either file depends on the mask being live.
That also matches what I found empirically when this flake bit me: go test ./htlcswitch/ without tags fails TestSwitchDustForwarding in ~20s with got totalDust=0 mSAT, expectedDust=70000000 mSAT ... timeout checking dust, and -tags=dev passes in ~6s. The failure is a silent no-op mask plus a downstream timeout, which is exactly what a fail-fast message fixes.
Two small notes, neither blocking:
make unit, which sets it" inline, since that is the common path and someone hitting this locally will otherwise assume they need to remember the flag rather than just use the make target.t.Fatalf("htlcswitch tests must be run with '-tags dev") calls with the helper. Good — the old ones had an unclosed quote, and centralising means the next hodl-dependent test gets the message for free.I could not find anything to object to. Shipping this would have saved me an hour I spent chasing the dust test as a regression before you identified it as a build-tag artifact.
Roasbeef
Running
go test ./htlcswitch/without-tags=devproduces a misleading failure. The productionhodl.Masknever reports a flag as active, so tests that setHodlMaskdon't fail where the problem is.TestSwitchDustForwarding, for example, waits about 20 seconds and then reportsgot totalDust=0 mSAT, expectedDust=70000000 mSAT ... timeout checking dust. That looks like a product bug, but nothing is wrong with the product code. The tests need the dev tag, whichmake unitand CI always set.In this PR, we add a small
requireDevBuildtest helper that callst.Fatalfwith a message saying the test depends on hodl flags and must be run with-tags=dev. It replaces the two inlinebuild.IsDevBuild()checks inlink_test.go, one of which had an unbalanced quote in its message. It is also added to the three other tests that set a hodl mask:TestSwitchDustForwarding,TestChannelLinkCleanupSpuriousResponsesandTestPipelineSettle.The helper fails the test instead of skipping it, so a missing tag can't turn into a silently passing run. Behavior with
-tags=devis unchanged.Verified: untagged runs of the five guarded tests now fail in under a millisecond with the explanation;
go test -tags=dev ./htlcswitch/ -count=1passes (108s);-run 'TestSwitchDustForwarding$' -count=3passes;gofmtandgo vet(tagged and untagged) are clean.Test-only change, so no release note.