wallet_child: one contract for a start that fails part way
Settle the contract the red feature-gated test was fighting, and make the code and both tests express it: a start that fails after the chain daemon came up is all or nothing, the same contract node::tests::a_missing_binary_fails_the_start_and_leaves_no_child asserts one level up. A daemon left running behind an error has no owner (the caller gets the error back, not the client), no handle to stop it, and holds 18081 against the next start; what a retry reuses is the chain datadir on disk, never a process that outlived its owner. start_with_creds already behaved that way, so this states the contract where the stop happens rather than changing it. in_process_source_launches_a_daemon_and_stop_shuts_it_down was red because its fake monero-wallet-rpc never binds the port its own readiness gate probes: start() returns that error, the test discarded it with `let _ =`, and it then asserted the daemon had survived a failed start. It now holds the published port the way the module's other start tests do (test_support::PublishedPortHold) and expects the start to succeed, with every assertion it had kept. The failure path gets its own test instead, which pins the tear-down: neither child running, the daemon's port closed, the chain datadir kept.
This commit is contained in:
parent
c776ea3e0c
commit
6c1fc5008a
1 changed files with 65 additions and 2 deletions
|
|
@ -527,6 +527,13 @@ impl WalletChild {
|
|||
Err(e) => {
|
||||
// A failure after the SOCKS child came up must not leave the
|
||||
// listener (or monerod) orphaned behind the error.
|
||||
//
|
||||
// That includes the in-process chain daemon, deliberately: this
|
||||
// call hands back the error instead of the client, so nothing
|
||||
// would own a daemon left running — and the next start could not
|
||||
// bind the port it was holding. The chain *datadir* is what
|
||||
// outlives a failed start and what a retry reuses, never a
|
||||
// daemon that no longer has an owner.
|
||||
let _ = self.stop();
|
||||
Err(e)
|
||||
}
|
||||
|
|
@ -2151,8 +2158,14 @@ mod tests {
|
|||
.with_wallet_rpc_bin(fake_bin(&dir, "monero-wallet-rpc", &rpc_log));
|
||||
|
||||
// The wallet RPC child is fake, so `start` reaches only the daemon: the
|
||||
// whole point of the in-process source is that the daemon *is* us.
|
||||
let _ = child.start(&store);
|
||||
// whole point of the in-process source is that the daemon *is* us. The
|
||||
// hold is what a `sh` fake cannot do itself — binding the port the gate
|
||||
// probes — so this test exercises the successful start it is named for
|
||||
// (see [`test_support::PublishedPortHold`]).
|
||||
let _hold = PublishedPortHold::watching(std::slice::from_ref(&rpc_log));
|
||||
child
|
||||
.start(&store)
|
||||
.expect("the daemon and the fake wallet RPC both come up");
|
||||
let addr = format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}");
|
||||
assert!(
|
||||
waits_for_tcp(&addr, Duration::from_secs(20)),
|
||||
|
|
@ -2174,6 +2187,56 @@ mod tests {
|
|||
assert!(closed, "the daemon's RPC listener outlived stop()");
|
||||
}
|
||||
|
||||
/// The other half of the same contract, and the reason `start_with_creds`
|
||||
/// stops what it started on *any* failure after the children came up: an
|
||||
/// in-process daemon survives a wallet-RPC failure only inside a `WalletChild`
|
||||
/// somebody still owns, and this call is about to hand the error back instead
|
||||
/// of the client — so a daemon left behind would have no owner, no handle and
|
||||
/// no way to stop it, while the next `start` could not bind its port. The
|
||||
/// chain datadir is what outlives a failed start; the process does not.
|
||||
/// `node::tests::a_missing_binary_fails_the_start_and_leaves_no_child`
|
||||
/// asserts the same contract one level up.
|
||||
///
|
||||
/// Nothing holds the fake wallet RPC's port here, so its readiness gate times
|
||||
/// out *after* the in-process daemon is already up — the failure path this
|
||||
/// pins. The error naming `monero-wallet-rpc` (not the chain daemon) is what
|
||||
/// proves the daemon had come up first.
|
||||
#[cfg(feature = "cuprate-daemon")]
|
||||
#[test]
|
||||
fn a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running() {
|
||||
let dir = tmp_dir("cuprate-late-failure");
|
||||
let store = open_store(&dir);
|
||||
let rpc_log = dir.join("wallet-rpc.argv");
|
||||
let child = WalletChild::new(in_process_source(&dir), dir.join("wallet"), None)
|
||||
.unwrap()
|
||||
.with_wallet_rpc_bin(fake_bin(&dir, "monero-wallet-rpc", &rpc_log));
|
||||
|
||||
let err = child
|
||||
.start(&store)
|
||||
.expect_err("a wallet RPC that never binds its port fails the start")
|
||||
.to_string();
|
||||
assert!(err.contains("monero-wallet-rpc"), "{err}");
|
||||
|
||||
assert!(
|
||||
!child.running(),
|
||||
"a failed start must not leave a daemon running: {err}"
|
||||
);
|
||||
assert!(
|
||||
dir.join("chain").exists(),
|
||||
"the chain datadir is the part that outlives a failed start"
|
||||
);
|
||||
let addr = format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}");
|
||||
let mut closed = false;
|
||||
for _ in 0..60 {
|
||||
if std::net::TcpStream::connect(&addr).is_err() {
|
||||
closed = true;
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(250));
|
||||
}
|
||||
assert!(closed, "the daemon's RPC listener outlived a failed start");
|
||||
}
|
||||
|
||||
fn probe_status(state: WalletChildState, height: u64, target_height: u64) -> WalletChildStatus {
|
||||
WalletChildStatus {
|
||||
state,
|
||||
|
|
|
|||
Loading…
Reference in a new issue