tests: write the fake child's argv log with one mv, not append-per-line
The wallet-child tests learn a spawned stand-in's port by polling its argv
log, and `fake_bin`/`fake_child_bin` truncated the log and then appended
one line per argument -- so a poller could read a prefix. A truncated port
is a *valid* u16 ("427" out of "42765"), so `wait_for_child_rpc_port`
happily returned a port nothing was listening on and the restart's
`open_wallet` died with `Connection refused` after its 10s budget; the
same prefix read is what `loopback_and_clearnet_remotes_carry_no_proxy...`
printed with its `--daemon-address` value missing.
Both tests failed on the first CI run of this branch (ci / test) and are
green in isolation, which is the signature of this race rather than of a
code defect. The argv now lands in the log with a single `mv`, so a reader
sees either no log or the complete one.
Measured with a tight read loop (argv-race-probe.sh): the append version
was caught mid-write 1/300 reads, the mv version 0/300.
This commit is contained in:
parent
59175f6931
commit
8d80a4fd55
2 changed files with 16 additions and 5 deletions
|
|
@ -3074,12 +3074,16 @@ pub(crate) mod tests {
|
||||||
/// A stand-in for `monero-wallet-rpc`: it records its argv, then does what
|
/// A stand-in for `monero-wallet-rpc`: it records its argv, then does what
|
||||||
/// the test needs. The wallet child spawns a real process, so this is the
|
/// the test needs. The wallet child spawns a real process, so this is the
|
||||||
/// only honest way to drive the start path offline.
|
/// only honest way to drive the start path offline.
|
||||||
|
///
|
||||||
|
/// The argv is `mv`d into place in one step rather than truncated and
|
||||||
|
/// appended: a poller must never read half of it. It did — the port was
|
||||||
|
/// parsed while it was still being written, so `42765` read as `427`, and
|
||||||
|
/// the mock was bound on a port nothing dialled.
|
||||||
fn fake_child_bin(dir: &Path, name: &str, log: &Path, body: &str) -> PathBuf {
|
fn fake_child_bin(dir: &Path, name: &str, log: &Path, body: &str) -> PathBuf {
|
||||||
std::fs::create_dir_all(dir).expect("fake bin dir");
|
std::fs::create_dir_all(dir).expect("fake bin dir");
|
||||||
let path = dir.join(name);
|
let path = dir.join(name);
|
||||||
let script = format!(
|
let script = format!(
|
||||||
"#!/bin/sh\n: > '{}'\nprintf '%s\\n' \"$0\" >> '{}'\nfor a in \"$@\"; do printf '%s\\n' \"$a\" >> '{}'; done\n{body}\n",
|
"#!/bin/sh\ntmp='{}'.$$\n: > \"$tmp\"\nprintf '%s\\n' \"$0\" >> \"$tmp\"\nfor a in \"$@\"; do printf '%s\\n' \"$a\" >> \"$tmp\"; done\nmv -f \"$tmp\" '{}'\n{body}\n",
|
||||||
log.display(),
|
|
||||||
log.display(),
|
log.display(),
|
||||||
log.display()
|
log.display()
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1233,17 +1233,24 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A stand-in for monerod / monero-wallet-rpc: records its argv, then parks.
|
/// A stand-in for monerod / monero-wallet-rpc: records its argv, then parks.
|
||||||
|
///
|
||||||
|
/// The argv lands in `<log>` with one `mv`, not a truncate-then-append: a
|
||||||
|
/// reader must never see half an argv. It did — the poll below could catch
|
||||||
|
/// `--rpc-bind-port` while the port was still being written and parse
|
||||||
|
/// `427` out of `42765`, a valid-but-wrong port, and the test then bound a
|
||||||
|
/// mock nobody dialled.
|
||||||
fn fake_bin(dir: &Path, name: &str, log: &Path) -> PathBuf {
|
fn fake_bin(dir: &Path, name: &str, log: &Path) -> PathBuf {
|
||||||
let path = dir.join(name);
|
let path = dir.join(name);
|
||||||
let mut f = fs::File::create(&path).unwrap();
|
let mut f = fs::File::create(&path).unwrap();
|
||||||
writeln!(f, "#!/bin/sh").unwrap();
|
writeln!(f, "#!/bin/sh").unwrap();
|
||||||
writeln!(f, ": > '{}'", log.display()).unwrap();
|
writeln!(f, "tmp='{}'.$$", log.display()).unwrap();
|
||||||
|
writeln!(f, ": > \"$tmp\"").unwrap();
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"for a in \"$@\"; do printf '%s\\n' \"$a\" >> '{}'; done",
|
"for a in \"$@\"; do printf '%s\\n' \"$a\" >> \"$tmp\"; done"
|
||||||
log.display()
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
writeln!(f, "mv -f \"$tmp\" '{}'", log.display()).unwrap();
|
||||||
writeln!(f, "sleep 30").unwrap();
|
writeln!(f, "sleep 30").unwrap();
|
||||||
drop(f);
|
drop(f);
|
||||||
let mut perms = fs::metadata(&path).unwrap().permissions();
|
let mut perms = fs::metadata(&path).unwrap().permissions();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue