T-190: M2.3q — tools/curate-etl: send-ilp CLI command wiring discover_ilp_shard_files + tcp_ilp_connector + send_ilp_shard_files into cli.rs + main.rs with parser tests and a loopback TcpListener end-to-end test (explicit --addr, no default target, no new crates, no bench changes, no live QuestDB)

This commit is contained in:
Studio 2026-12-02 20:42:20 -05:00 • committed by Boki
parent b51ce9b22b
commit e9fbea3dda
7 changed files with 703 additions and 4 deletions

View file

@ -1742,3 +1742,133 @@ fn bench_curate_shorts_command_small_run_is_deterministic_and_reports_stages() {
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
}
#[test]
fn send_ilp_cli_help_missing_flag_success_and_partial_error_routing() {
use std::io::{self, Read};
use std::net::TcpListener;
use std::thread;
use std::time::{Duration, Instant};
// 1. --help lists send-ilp, required flags, and delivery caveat.
let help = run(&["--help"]);
assert!(help.status.success(), "{}", stderr(&help));
let help_text = stdout(&help);
assert!(help_text.contains("send-ilp"), "{help_text}");
assert!(
help_text.contains("--dir")
&& help_text.contains("--prefix")
&& help_text.contains("--addr"),
"{help_text}"
);
assert!(help_text.contains("PGWire"), "{help_text}");
assert!(help_text.contains("10.2.0"), "{help_text}");
// 2. Missing --addr exits non-zero with error + Usage on stderr and empty stdout.
let missing_addr = run(&["send-ilp", "--dir", "/tmp/shards", "--prefix", "fx_1m"]);
assert!(!missing_addr.status.success());
assert_eq!(missing_addr.status.code(), Some(1));
assert!(stdout(&missing_addr).is_empty());
let missing_err = stderr(&missing_addr);
assert!(
missing_err.contains("error: missing required flag '--addr'"),
"{missing_err}"
);
assert!(missing_err.contains("Usage:"), "{missing_err}");
assert!(missing_err.contains("send-ilp"), "{missing_err}");
// 3. Binary success path over loopback prints format_ilp_send_report to stdout.
let dir = CliTempDir::new("send-ilp-bin");
let payload0 = b"fx_1m,pair=USDCAD close=1.38 1700000000000000t\n";
let payload1 = b"";
write_file(&dir.path.join("fx_1m.shard-00.ilp"), payload0);
write_file(&dir.path.join("fx_1m.shard-01.ilp"), payload1);
let listener = TcpListener::bind("127.0.0.1:0").expect("bind loopback listener");
let listen_addr = listener.local_addr().expect("local addr");
listener
.set_nonblocking(true)
.expect("set loopback listener nonblocking");
let server = thread::spawn(move || {
let deadline = Instant::now() + Duration::from_secs(5);
let mut received = Vec::with_capacity(2);
for accepted in 0..2 {
let mut stream = loop {
match listener.accept() {
Ok((s, _)) => {
s.set_nonblocking(false).expect("set stream blocking");
break s;
}
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {
assert!(
Instant::now() < deadline,
"timed out waiting for connection {accepted}/2"
);
thread::sleep(Duration::from_millis(5));
}
Err(err) => panic!("accept failed: {err}"),
}
};
stream
.set_read_timeout(Some(Duration::from_secs(3)))
.expect("set read timeout");
let mut buf = Vec::new();
stream.read_to_end(&mut buf).expect("read shard to EOF");
received.push(buf);
}
received
});
let ok_out = run(&[
"send-ilp",
"--dir",
dir.path.to_str().unwrap(),
"--prefix",
"fx_1m",
"--addr",
&listen_addr.to_string(),
]);
let mut received = server.join().expect("join server");
received.sort();
let mut expected_payloads = vec![payload0.to_vec(), payload1.to_vec()];
expected_payloads.sort();
assert_eq!(received, expected_payloads);
assert!(ok_out.status.success(), "{}", stderr(&ok_out));
assert!(stderr(&ok_out).is_empty(), "{}", stderr(&ok_out));
assert_eq!(
stdout(&ok_out),
format!(
"curate-etl ilp-send\n ilp_send: shards=2 total_bytes_sent={} per_shard_bytes=00={},01=0\n",
payload0.len(),
payload0.len()
)
);
// 4. Runtime connect failure prints error + formatted partial report to stderr, empty stdout.
let dead_listener = TcpListener::bind("127.0.0.1:0").expect("bind ephemeral port");
let dead_addr = dead_listener.local_addr().expect("ephemeral addr");
drop(dead_listener);
let fail_out = run(&[
"send-ilp",
"--dir",
dir.path.to_str().unwrap(),
"--prefix",
"fx_1m",
"--addr",
&dead_addr.to_string(),
]);
assert!(!fail_out.status.success());
assert_eq!(fail_out.status.code(), Some(1));
assert!(stdout(&fail_out).is_empty());
let fail_err = stderr(&fail_out);
assert!(fail_err.contains("error: ILP shard 0"), "{fail_err}");
assert!(
fail_err.contains(
"curate-etl ilp-send\n ilp_send: shards=2 total_bytes_sent=0 per_shard_bytes=00=0,01=0"
),
"{fail_err}"
);
assert!(!fail_err.contains("Usage:"), "{fail_err}");
}