Skip to content

integration/rpctest: improve rpctest harness#2571

Open
allocz wants to merge 1 commit into
btcsuite:masterfrom
allocz:improve_rpctest_harness
Open

integration/rpctest: improve rpctest harness#2571
allocz wants to merge 1 commit into
btcsuite:masterfrom
allocz:improve_rpctest_harness

Conversation

@allocz

@allocz allocz commented Jul 7, 2026

Copy link
Copy Markdown

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

  1. Debug event stream: connect to btcd and receive debug events.
  2. Harness teardown: stops btcd returning the exit code, but allow stopping
    without cleaning up node data, enabling the test of scenarios where btcd
    exits with error or scenarios where the node should be restarted.
  3. Harness start: allow the harness to be started again after teardown is
    called.
  4. Change Harness related procedure signatures: pass opts as a struct instead
    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

make unit
make unit-cover
make unit-race

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

@allocz allocz force-pushed the improve_rpctest_harness branch from 14d655f to e5dfa5d Compare July 8, 2026 11:17
@allocz allocz mentioned this pull request Jul 8, 2026
7 tasks
Comment thread integration/rpctest/rpc_harness.go Outdated
Comment thread integration/rpctest/node.go
Comment thread debugstream/client.go Outdated
Comment thread debugstream/client.go Outdated
Comment thread debugstream/common.go Outdated
@allocz allocz force-pushed the improve_rpctest_harness branch 2 times, most recently from e05176c to f4b587b Compare July 11, 2026 23:39
@allocz

allocz commented Jul 12, 2026

Copy link
Copy Markdown
Author

For now I think that we achieved what was proposed. Ready for review again. Thanks to @TechLateef for providing several fixes and improvements.

@allocz allocz force-pushed the improve_rpctest_harness branch 3 times, most recently from b35585d to fb75252 Compare July 12, 2026 02:36
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.
@allocz allocz force-pushed the improve_rpctest_harness branch from fb75252 to e7fe6fd Compare July 12, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants