Skip to content

integration/rpctest: improve test harness#7

Open
allocz wants to merge 1 commit into
masterfrom
improve_rpctest_harness
Open

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

Conversation

@allocz

@allocz allocz commented Jun 30, 2026

Copy link
Copy Markdown
Owner

As discussed in btcsuite#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 New() signature: pass opts as a struct instead of having to pass multiple zero values to get default initialization.

@allocz allocz force-pushed the improve_rpctest_harness branch from 287ca98 to f8932e0 Compare July 3, 2026 20:42
@allocz allocz changed the title integration/rpctest: add log assertion to Harness integration/rpctest: improve test harness Jul 3, 2026
@allocz allocz force-pushed the improve_rpctest_harness branch 8 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.

1 participant