Repository navigation
test: wait for lnd's server before tests stop lnd - #295
Conversation
viberaven
left a comment
There was a problem hiding this comment.
Waiting for SERVER_ACTIVE covers the direct wallet stop in the full netnsRegtest scenario. I found two paths where the tests can still stop lnd during server startup. The nine runner tests passed locally, and the PR’s default and netnsRegtest VM jobs passed.
1c73c0b to
d8f78fe
Compare
|
Thanks, you're right on both. Both are fixed in d8f78fe.
|
viberaven
left a comment
There was a problem hiding this comment.
Approved d8f78fe7. I reran both cases on KVM. With lnd initially down, config-replace started it and waited for SERVER_ACTIVE before each bitcoind stop and each direct lnd stop. Running lnd-wallet-init alone on regtestBase also passed, and all three waits used lncli state.
The CI logs confirm that restart-bitcoind waits before both the stop and the restart on netnsRegtest, and the default VM still uses getinfo. Regtest VM log · Default VM log
Both earlier findings are fixed. GitHub denied my requests to resolve the conversations with this read-only account. The PR author or a maintainer can close them. Bitcoind stop · Focused regtest run
Tests waited for lnd with `lncli getinfo` or `systemctl start`. lnd answers
RPCs and notifies systemd before its server has started all subsystems. On
regtest, a stop or SIGTERM in that window can make lnd panic ("unable to
subscribe to chans: subscription server shutting down"). The failed exit
then fails `lnd-restart-on-clean-exit`, which checks that lnd never failed
during the boot. This happened in `lnd-wallet-init`, which stops lnd right
after a new wallet comes up.
Add `wait_for_lnd_server`, which waits for `lncli state` to report
SERVER_ACTIVE when the regtest fixture has mined blocks (`num_blocks`). lnd
starts its server only once its chain has synced. Without these blocks, as
on the test mainnet, lnd never starts its server and can't panic this way,
so the helper keeps the `getinfo` wait. The fixture's data stays the same
when a run selects a subset of the tests.
Use it in the tests that run before that check and stop, restart or
terminate lnd: `config-replace`, `lnd-wallet-init` and
`rtl-stops-with-backend`. lnd requires bitcoind and stops with it, so
`restart-bitcoind` and `config-replace` also wait before they stop
bitcoind. Both start lnd before that wait, because lnd can be down there,
for example when a run leaves out test `lnd`. `restart-bitcoind` reads
whether lnd is enabled from a new `test.data.restart-bitcoind.lnd`.
`lnd-macaroon-revocation` runs after that check and has its own, so its
stops of lnd are left for a separate change. `lnd-create-macaroons` also
restarts lnd right after a start once it deletes stale root keys, and only
a module change can close that window. `backups` stops bitcoind before the
check too, but it runs only on the test mainnet.
Also tell test authors about the helper in `test/README.md`.
Assisted-by: Claude Code (Claude Opus 5.5)
d8f78fe to
c9ecbe6
Compare
netnsRegtestfailed once on #291 because lnd panicked.lnd-wallet-initstopped lnd right after a new wallet came up, and lnd crashed on that early stop withunable to subscribe to chans: subscription server shutting down.lnd-restart-on-clean-exitthen found the failed exit in lnd's journal.lnd answers RPCs and notifies systemd before its server has started all subsystems, so neither
lncli getinfonorsystemctl startcloses that window. This PR:wait_for_lnd_servertotest/suite/helpers.py. When the regtest fixture has mined blocks (num_blocks), it waits untillncli statereportsSERVER_ACTIVE. lnd starts its server only once its chain has synced. Without these blocks, as on the test mainnet, lnd never starts its server and can't panic this way, so the helper keeps thegetinfowait there. The fixture's data doesn't change when a run selects a subset of the tests.lnd-restart-on-clean-exitand stop, restart or terminate lnd. These areconfig-replace,lnd-wallet-initandrtl-stops-with-backend.restart-bitcoindandconfig-replacestop bitcoind, because lnd requires bitcoind and stops with it. Both start lnd before that wait, because lnd can be down there.restart-bitcoindreads whether lnd is enabled from a newtest.data.restart-bitcoind.lnd, so this also works when a run leaves out testlnd.test/README.md.Testing
netnsRegtestanddefaultpass on a KVM host. In thenetnsRegtestlog, theSERVER_ACTIVEwait comes right before each stop of bitcoind inrestart-bitcoindandconfig-replace.regtestBasewith lnd also pass.lnd-wallet-initalone. All three of its waits uselncli state.config-replacealone, with lnd down when the test starts.restart-bitcoindandlnd-restart-on-clean-exit, without testlnd. Both stops of bitcoind wait forSERVER_ACTIVE. Right after boot, the first wait took about 2.5 s, so the stop used to land in that window.lnd-macaroon-revocationruns afterlnd-restart-on-clean-exitand has its own failure check, so I left its stops of lnd for a separate change.lnd-create-macaroonsalso restarts lnd right after a start once it deletes stale root keys. Only a module change can close that window, and that wait needs a timeout, because a node that's still syncing never starts its server.backupsstops bitcoind too, but it runs only on the test mainnet.Written with Claude Opus 5.5, reviewed with Claude Fable 5.2.