integration/rpctest: improve rpctest harness#2571
Open
allocz wants to merge 1 commit into
Open
Conversation
14d655f to
e5dfa5d
Compare
TechLateef
reviewed
Jul 10, 2026
TechLateef
reviewed
Jul 10, 2026
TechLateef
reviewed
Jul 10, 2026
TechLateef
reviewed
Jul 10, 2026
74ffcc5 to
466eeb7
Compare
7 tasks
TechLateef
reviewed
Jul 11, 2026
e05176c to
f4b587b
Compare
Author
|
For now I think that we achieved what was proposed. Ready for review again. Thanks to @TechLateef for providing several fixes and improvements. |
b35585d to
fb75252
Compare
integration/rpctest: Fixed a goroutine leak caused by the [memWallet.Start] procedure which was spinning up a goroutine that was never terminated. Also, added a new method [memWallet.Stop], which is called by [Harness.TearDown], sending a stop request to the wallet and waiting until the wallet stops. Also added a test to [TestHarness] to catch goroutine leakage. Changed [New], initializing the [Harness] with an options struct instead of several fields that may be set to the zero value of the type, cleaning up the API and improving extensibility. Previously [Harness.SetUp] was receiving a boolean to generate a test chain and a integer for the required number of mature outputs, but internally, the test chain was being generated only if the number of mature outputs was different than zero and the boolean was true, this means that we can remove the boolean and create the test chain only when the required numbed of mature UTXO's is greater than zero. Add configuration options to [Harness.SetUp] and [Harness.TearDown], enabling future functionality extension without breaking changes and also avoiding the need of passing zero value arguments to get the default config. Add option to [Harness.SetUp] allowing to skip starting RPC and Wallet, avoiding errors being returned in scenarios where the node shuts down before starting the RPC, like when dropping cfindex with --dropcfindex. Add option to [Harness.SetUp] allowing to skip the wait for memwallet to sync up to the node best height, avoiding blocking forever when the node is shut down before the wallet receives all block connected events, because in this case wallet best height would be less than the node best height. Pass btcd args in [Harness.SetUp] instead of [New], enabling restarting the node with different configuration but same state. Make [Harness.TearDown] return error if the btcd process exits with non zero status code, previously the error returned by [exec.Cmd.Wait] was being ignored. This change enables tests to assert if the node stopped successfully or not. NoNodeCleanup option added to [Harness.TearDown], which makes possible to write tests that restart the node while keeping state. NoShutdownSignal option added to [Harness.Teardown], which instead of sending termination signal, blocks until the node process finishes enabling testing scenarios where the node process exits by itself. Added debug handler to [New] options, allowing integration tests to easily process debug events. The btcd executable used by the Harness is now being built with the debug tag, but the debug stream will be started only if the debug handler is also passed to the Harness. debugstream: The package debugstream provides two utility types, [Stream] and [Client]. [Stream] listens on a TCP endpoint and broadcasts events to connected clients. The [Event] type has a uint64 code and a byte slice data fields . The [Stream] implementation is used only when btcd is compiled with the debug tag, otherwise a nop implementation is used. [Client] connects with [Stream] via TCP and starts receiving the events , which are passed into a handler callback, allowing assertions inside tests. All events broadcasted in the stream are stored in memory and sent to all clients, even if the client connects after the broadcast of some events, it still receives all of them. btcd: btcd integrated with debugstream, so that we can send debug events and improve testing capabilities. The hidden flag --debugstream=<host:port> starts the [Stream] when btcd is compiled with the debug tag, otherwise it is a NOP operation, using StreamNOP, which does nothing.
fb75252 to
e7fe6fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Description
The main motivation of this PR is to improve the process of writing integration
tests, currently there's no way to write complex tests in a simple way.
As discussed in #2560.
Changes
without cleaning up node data, enabling the test of scenarios where btcd
exits with error or scenarios where the node should be restarted.
called.
of having to pass multiple zero values to get default initialization.
The debug event stream is replaced by a NOP implementation when the compile tag
debug is not defined, so that the compiler can optimize out all the debug event
broadcast calls. Also, the hidden flag --debugstream=host:port should be used
to start the event stream.
There's also bugfixes, the complete changelog is in the commit message.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.