699 lines
25 KiB
Rust
699 lines
25 KiB
Rust
//! QA end-to-end tests for the `curate-etl` binary (T-47 / M1.2a CLI contract).
|
|
|
|
use std::fs::{self, File};
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::process::{Command, Output};
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
|
|
use bson::raw::{cstr, RawDocumentBuf};
|
|
|
|
fn run(args: &[&str]) -> Output {
|
|
Command::new(env!("CARGO_BIN_EXE_curate-etl"))
|
|
.args(args)
|
|
.output()
|
|
.expect("spawn curate-etl binary")
|
|
}
|
|
|
|
fn stdout(o: &Output) -> String {
|
|
String::from_utf8_lossy(&o.stdout).into_owned()
|
|
}
|
|
|
|
fn stderr(o: &Output) -> String {
|
|
String::from_utf8_lossy(&o.stderr).into_owned()
|
|
}
|
|
|
|
#[test]
|
|
fn no_args_and_help_print_usage_and_succeed() {
|
|
for args in [&[][..], &["--help"][..], &["-h"][..]] {
|
|
let out = run(args);
|
|
assert!(out.status.success(), "{args:?}: {}", stderr(&out));
|
|
let text = stdout(&out);
|
|
assert!(text.contains("Usage:"), "{args:?}: {text}");
|
|
assert!(text.contains("curate-bars-1d"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-curate-bars-cmd"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-split"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-corporate-actions"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-fx"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-events"), "{args:?}: {text}");
|
|
assert!(text.contains("bench-curate-fx"), "{args:?}: {text}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn version_prints_package_name_and_version() {
|
|
for flag in ["--version", "-V"] {
|
|
let out = run(&[flag]);
|
|
assert!(out.status.success());
|
|
assert_eq!(
|
|
stdout(&out).trim(),
|
|
format!("curate-etl {}", env!("CARGO_PKG_VERSION"))
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_invocations_exit_nonzero_with_usage_on_stderr() {
|
|
for args in [
|
|
&["--version", "--offine"][..],
|
|
&["--help", "--bad"][..],
|
|
&["bench-split", "abc"][..],
|
|
&["bench-split", "0"][..],
|
|
&["bench-split", "-5"][..],
|
|
&["bench-split", "10", "20"][..],
|
|
&["bench-corporate-actions", "abc"][..],
|
|
&["bench-corporate-actions", "0"][..],
|
|
&["bench-corporate-actions", "-5"][..],
|
|
&["bench-corporate-actions", "10", "20"][..],
|
|
&["bench-fx", "abc"][..],
|
|
&["bench-fx", "0"][..],
|
|
&["bench-fx", "-5"][..],
|
|
&["bench-fx", "10", "20"][..],
|
|
&["bench-events", "abc"][..],
|
|
&["bench-events", "0"][..],
|
|
&["bench-events", "-5"][..],
|
|
&["bench-events", "10", "20"][..],
|
|
&["bench-curate-fx", "abc"][..],
|
|
&["bench-curate-fx", "0"][..],
|
|
&["bench-curate-fx", "-5"][..],
|
|
&["bench-curate-fx", "10", "20"][..],
|
|
&["--unknown"][..],
|
|
&["export"][..],
|
|
] {
|
|
let out = run(args);
|
|
assert!(!out.status.success(), "{args:?} should fail");
|
|
assert_eq!(out.status.code(), Some(1), "{args:?}");
|
|
let err = stderr(&out);
|
|
assert!(err.contains("error:"), "{args:?}: {err}");
|
|
assert!(err.contains("Usage:"), "{args:?}: {err}");
|
|
assert!(stdout(&out).is_empty(), "{args:?} wrote to stdout");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn bench_split_small_run_is_headless_deterministic_and_reports_rates() {
|
|
let a = run(&["bench-split", "1000"]);
|
|
let b = run(&["bench-split", "1000"]);
|
|
assert!(a.status.success(), "{}", stderr(&a));
|
|
assert!(b.status.success(), "{}", stderr(&b));
|
|
|
|
let text = stdout(&a);
|
|
assert!(
|
|
text.contains("keys=20000 keys_with_splits=12153 events=18999"),
|
|
"{text}"
|
|
);
|
|
assert!(text.contains("rows=1000 "), "{text}");
|
|
assert!(text.contains("rows/s"), "{text}");
|
|
assert!(text.contains("ns/row"), "{text}");
|
|
assert!(text.contains("checksum=20285840610.475"), "{text}");
|
|
|
|
let checksum = |s: &str| {
|
|
s.split_whitespace()
|
|
.find(|t| t.starts_with("checksum="))
|
|
.map(str::to_owned)
|
|
};
|
|
assert_eq!(checksum(&text), checksum(&stdout(&b)));
|
|
}
|
|
|
|
#[test]
|
|
fn bench_corporate_actions_small_run_is_headless_deterministic_and_reports_rates() {
|
|
let a = run(&["bench-corporate-actions", "1000"]);
|
|
let b = run(&["bench-corporate-actions", "1000"]);
|
|
assert!(a.status.success(), "{}", stderr(&a));
|
|
assert!(b.status.success(), "{}", stderr(&b));
|
|
assert!(stderr(&a).is_empty(), "unexpected stderr: {}", stderr(&a));
|
|
assert!(stderr(&b).is_empty(), "unexpected stderr: {}", stderr(&b));
|
|
|
|
let text_a = stdout(&a);
|
|
let text_b = stdout(&b);
|
|
assert!(
|
|
text_a.contains("curate-etl bench-corporate-actions"),
|
|
"{text_a}"
|
|
);
|
|
assert!(text_a.contains("events=1000 "), "{text_a}");
|
|
assert!(text_a.contains("keys=20000"), "{text_a}");
|
|
assert!(text_a.contains("rows_out="), "{text_a}");
|
|
assert!(text_a.contains("events/s"), "{text_a}");
|
|
assert!(text_a.contains("ns/event"), "{text_a}");
|
|
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
|
assert!(text_a.contains("stats: split_noops="), "{text_a}");
|
|
|
|
let field = |s: &str, prefix: &str| {
|
|
s.split_whitespace()
|
|
.find(|t| t.starts_with(prefix))
|
|
.map(str::to_owned)
|
|
};
|
|
let checksum_a = field(&text_a, "checksum=");
|
|
let checksum_b = field(&text_b, "checksum=");
|
|
assert!(checksum_a.is_some(), "{text_a}");
|
|
assert_eq!(checksum_a, checksum_b);
|
|
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
|
}
|
|
|
|
#[test]
|
|
fn bench_fx_small_run_is_headless_deterministic_and_reports_rates() {
|
|
let a = run(&["bench-fx", "1000"]);
|
|
let b = run(&["bench-fx", "1000"]);
|
|
assert!(a.status.success(), "{}", stderr(&a));
|
|
assert!(b.status.success(), "{}", stderr(&b));
|
|
assert!(stderr(&a).is_empty(), "unexpected stderr: {}", stderr(&a));
|
|
assert!(stderr(&b).is_empty(), "unexpected stderr: {}", stderr(&b));
|
|
|
|
let text_a = stdout(&a);
|
|
let text_b = stdout(&b);
|
|
assert!(text_a.contains("curate-etl bench-fx"), "{text_a}");
|
|
assert!(text_a.contains("rows=1000 "), "{text_a}");
|
|
assert!(text_a.contains("rows_out="), "{text_a}");
|
|
assert!(text_a.contains("rows/s"), "{text_a}");
|
|
assert!(text_a.contains("lookups=1000000 "), "{text_a}");
|
|
assert!(text_a.contains("lookups/s"), "{text_a}");
|
|
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
|
assert!(text_a.contains("stats: eod_invalid="), "{text_a}");
|
|
|
|
let field = |s: &str, prefix: &str| {
|
|
s.split_whitespace()
|
|
.find(|t| t.starts_with(prefix))
|
|
.map(str::to_owned)
|
|
};
|
|
let checksum_a = field(&text_a, "checksum=");
|
|
let checksum_b = field(&text_b, "checksum=");
|
|
assert!(checksum_a.is_some(), "{text_a}");
|
|
assert_eq!(checksum_a, checksum_b);
|
|
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
|
}
|
|
|
|
#[test]
|
|
fn bench_events_small_run_is_headless_deterministic_and_reports_rates() {
|
|
let a = run(&["bench-events", "1000"]);
|
|
let b = run(&["bench-events", "1000"]);
|
|
assert!(a.status.success(), "{}", stderr(&a));
|
|
assert!(b.status.success(), "{}", stderr(&b));
|
|
assert!(stderr(&a).is_empty(), "unexpected stderr: {}", stderr(&a));
|
|
assert!(stderr(&b).is_empty(), "unexpected stderr: {}", stderr(&b));
|
|
|
|
let text_a = stdout(&a);
|
|
let text_b = stdout(&b);
|
|
assert!(text_a.contains("curate-etl bench-events"), "{text_a}");
|
|
assert!(text_a.contains("rows=1000 "), "{text_a}");
|
|
assert!(text_a.contains("rows_out="), "{text_a}");
|
|
assert!(text_a.contains("rows/s"), "{text_a}");
|
|
assert!(text_a.contains("ns/row"), "{text_a}");
|
|
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
|
assert!(text_a.contains("stats: malformed_ts="), "{text_a}");
|
|
|
|
let field = |s: &str, prefix: &str| {
|
|
s.split_whitespace()
|
|
.find(|t| t.starts_with(prefix))
|
|
.map(str::to_owned)
|
|
};
|
|
let checksum_a = field(&text_a, "checksum=");
|
|
let checksum_b = field(&text_b, "checksum=");
|
|
assert!(checksum_a.is_some(), "{text_a}");
|
|
assert_eq!(checksum_a, checksum_b);
|
|
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
|
}
|
|
|
|
#[test]
|
|
fn bench_curate_fx_small_run_is_headless_deterministic_and_reports_rates() {
|
|
let a = run(&["bench-curate-fx", "2000"]);
|
|
let b = run(&["bench-curate-fx", "2000"]);
|
|
assert!(a.status.success(), "{}", stderr(&a));
|
|
assert!(b.status.success(), "{}", stderr(&b));
|
|
assert!(stderr(&a).is_empty(), "unexpected stderr: {}", stderr(&a));
|
|
assert!(stderr(&b).is_empty(), "unexpected stderr: {}", stderr(&b));
|
|
|
|
let text_a = stdout(&a);
|
|
let text_b = stdout(&b);
|
|
assert!(text_a.contains("curate-etl bench-curate-fx"), "{text_a}");
|
|
assert!(text_a.contains("rows=2000 "), "{text_a}");
|
|
assert!(text_a.contains("stage:"), "{text_a}");
|
|
assert!(text_a.contains("parquet:"), "{text_a}");
|
|
assert!(text_a.contains("total:"), "{text_a}");
|
|
assert!(text_a.contains("overlap:"), "{text_a}");
|
|
assert!(text_a.contains("rows/s"), "{text_a}");
|
|
assert!(text_a.contains("bytes="), "{text_a}");
|
|
assert!(text_a.contains("checksum=0x"), "{text_a}");
|
|
|
|
let field = |s: &str, prefix: &str| {
|
|
s.split_whitespace()
|
|
.find(|t| t.starts_with(prefix))
|
|
.map(str::to_owned)
|
|
};
|
|
let checksum_a = field(&text_a, "checksum=");
|
|
let checksum_b = field(&text_b, "checksum=");
|
|
assert!(checksum_a.is_some(), "{text_a}");
|
|
assert_eq!(checksum_a, checksum_b);
|
|
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
|
assert_eq!(field(&text_a, "bytes="), field(&text_b, "bytes="));
|
|
}
|
|
|
|
static CLI_TEST_DIR_SEQ: AtomicU64 = AtomicU64::new(0);
|
|
|
|
struct CliTempDir {
|
|
path: PathBuf,
|
|
}
|
|
|
|
impl CliTempDir {
|
|
fn new(tag: &str) -> Self {
|
|
let pid = std::process::id();
|
|
let seq = CLI_TEST_DIR_SEQ.fetch_add(1, Ordering::Relaxed);
|
|
let path = std::env::temp_dir().join(format!("curate-etl-cli-{tag}-{pid}-{seq}"));
|
|
fs::create_dir_all(&path).expect("create cli test temp dir");
|
|
Self { path }
|
|
}
|
|
}
|
|
|
|
impl Drop for CliTempDir {
|
|
fn drop(&mut self) {
|
|
let _ = fs::remove_dir_all(&self.path);
|
|
}
|
|
}
|
|
|
|
fn write_file(path: &std::path::Path, bytes: &[u8]) {
|
|
let mut f = File::create(path).expect("create file");
|
|
f.write_all(bytes).expect("write file");
|
|
}
|
|
|
|
fn make_eod_doc(code: &str, date: &str, close: f64, volume: f64) -> Vec<u8> {
|
|
let mut doc = RawDocumentBuf::new();
|
|
doc.append(cstr!("eodSearchCode"), code);
|
|
doc.append(cstr!("date"), date);
|
|
doc.append(cstr!("open"), close);
|
|
doc.append(cstr!("high"), close + 1.0);
|
|
doc.append(cstr!("low"), close - 1.0);
|
|
doc.append(cstr!("close"), close);
|
|
doc.append(cstr!("volume"), volume);
|
|
doc.into_bytes()
|
|
}
|
|
|
|
fn make_split_doc(code: &str, date: &str, ratio: f64) -> Vec<u8> {
|
|
let mut doc = RawDocumentBuf::new();
|
|
doc.append(cstr!("qmSearchCode"), code);
|
|
doc.append(cstr!("date"), date);
|
|
doc.append(cstr!("splitratio"), ratio);
|
|
doc.into_bytes()
|
|
}
|
|
|
|
#[test]
|
|
fn curate_bars_1d_cli_flag_errors_exit_nonzero_with_usage() {
|
|
for args in [
|
|
&["curate-bars-1d"][..],
|
|
&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
"e.bson",
|
|
"--qm-splits",
|
|
"s.bson",
|
|
"--provider-mapping",
|
|
"m.tsv",
|
|
"--listing-currencies",
|
|
"c.tsv",
|
|
][..],
|
|
&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
"e.bson",
|
|
"--eod-prices",
|
|
"e2.bson",
|
|
"--qm-splits",
|
|
"s.bson",
|
|
"--provider-mapping",
|
|
"m.tsv",
|
|
"--listing-currencies",
|
|
"c.tsv",
|
|
"--out",
|
|
"o",
|
|
][..],
|
|
&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
"e.bson",
|
|
"--qm-splits",
|
|
"s.bson",
|
|
"--provider-mapping",
|
|
"m.tsv",
|
|
"--listing-currencies",
|
|
"c.tsv",
|
|
"--out",
|
|
"o",
|
|
"--bogus",
|
|
"1",
|
|
][..],
|
|
&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
"e.bson",
|
|
"--qm-splits",
|
|
"s.bson",
|
|
"--provider-mapping",
|
|
"m.tsv",
|
|
"--listing-currencies",
|
|
"c.tsv",
|
|
"--out",
|
|
"o",
|
|
"--rel-tolerance",
|
|
"not-a-number",
|
|
][..],
|
|
] {
|
|
let out = run(args);
|
|
assert!(!out.status.success(), "{args:?} should fail");
|
|
assert_eq!(out.status.code(), Some(1), "{args:?}");
|
|
assert!(stdout(&out).is_empty(), "{args:?} wrote to stdout");
|
|
let err = stderr(&out);
|
|
assert!(err.contains("error:"), "{args:?}: {err}");
|
|
assert!(err.contains("Usage:"), "{args:?}: {err}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn curate_bars_1d_cli_happy_path_and_determinism_with_shuffled_bson() {
|
|
let dir = CliTempDir::new("happy");
|
|
let eod_a = dir.path.join("eod_a.bson");
|
|
let eod_b = dir.path.join("eod_b.bson");
|
|
let splits_a = dir.path.join("splits_a.bson");
|
|
let splits_b = dir.path.join("splits_b.bson");
|
|
let map_path = dir.path.join("provider_mapping.tsv");
|
|
let curr_path = dir.path.join("listing_currencies.tsv");
|
|
let out_a = dir.path.join("out_a");
|
|
let out_b = dir.path.join("out_b");
|
|
|
|
write_file(
|
|
&map_path,
|
|
b"eod\tNVDA.US\t2010-01-01\t\t100\nqm\tNVDA:US\t2010-01-01\t\t100\n",
|
|
);
|
|
write_file(&curr_path, b"100\tUSD\n");
|
|
|
|
let d1 = make_eod_doc("NVDA.US", "2024-06-07", 1208.88, 410_000_000.0);
|
|
let d2 = make_eod_doc("NVDA.US", "2024-06-10", 121.79, 310_000_000.0);
|
|
write_file(&eod_a, &[d1.as_slice(), d2.as_slice()].concat());
|
|
write_file(&eod_b, &[d2.as_slice(), d1.as_slice()].concat());
|
|
|
|
let s1 = make_split_doc("NVDA:US", "2024-06-10", 10.0);
|
|
write_file(&splits_a, &s1);
|
|
write_file(&splits_b, &s1);
|
|
|
|
let run_a = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_a.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_a.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_path.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_path.to_str().unwrap(),
|
|
"--out",
|
|
out_a.to_str().unwrap(),
|
|
]);
|
|
assert!(run_a.status.success(), "{}", stderr(&run_a));
|
|
assert!(stderr(&run_a).is_empty(), "{}", stderr(&run_a));
|
|
|
|
let run_b = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_b.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_b.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_path.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_path.to_str().unwrap(),
|
|
"--out",
|
|
out_b.to_str().unwrap(),
|
|
]);
|
|
assert!(run_b.status.success(), "{}", stderr(&run_b));
|
|
assert!(stderr(&run_b).is_empty(), "{}", stderr(&run_b));
|
|
|
|
let strip_timing = |s: &str| {
|
|
s.lines()
|
|
.filter(|l| !l.trim_start().starts_with("timing:"))
|
|
.collect::<Vec<_>>()
|
|
.join("\n")
|
|
};
|
|
let text_a = stdout(&run_a);
|
|
let text_b = stdout(&run_b);
|
|
assert!(text_a.contains("curate-etl curate-bars-1d"), "{text_a}");
|
|
assert!(text_a.contains("rows_written=2"), "{text_a}");
|
|
assert!(text_a.contains("2024=2"), "{text_a}");
|
|
assert_eq!(strip_timing(&text_a), strip_timing(&text_b));
|
|
|
|
let pq_a = fs::read(out_a.join("bars_1d/year=2024/part.parquet")).unwrap();
|
|
let pq_b = fs::read(out_b.join("bars_1d/year=2024/part.parquet")).unwrap();
|
|
assert_eq!(pq_a, pq_b);
|
|
}
|
|
|
|
#[test]
|
|
fn curate_bars_1d_cli_runtime_failures_single_line_stderr_and_no_partial_dataset() {
|
|
let dir = CliTempDir::new("fail");
|
|
let eod_ok = dir.path.join("eod.bson");
|
|
let splits_ok = dir.path.join("splits.bson");
|
|
let map_ok = dir.path.join("map.tsv");
|
|
let curr_ok = dir.path.join("curr.tsv");
|
|
write_file(&eod_ok, &make_eod_doc("NVDA.US", "2024-06-07", 100.0, 1000.0));
|
|
write_file(&splits_ok, b"");
|
|
write_file(&map_ok, b"eod\tNVDA.US\t2020-01-01\t\t1\n");
|
|
write_file(&curr_ok, b"1\tUSD\n");
|
|
|
|
// 1. Malformed TSV line -> names path and 1-based line number, single-line stderr, no bars_1d.
|
|
let bad_map = dir.path.join("bad_map.tsv");
|
|
write_file(&bad_map, b"eod\tNVDA.US\t2020-01-01\t\t1\nbad_line\n");
|
|
let out1 = dir.path.join("out1");
|
|
let res = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_ok.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
bad_map.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out1.to_str().unwrap(),
|
|
]);
|
|
assert!(!res.status.success());
|
|
assert!(stdout(&res).is_empty());
|
|
let err = stderr(&res);
|
|
assert_eq!(err.lines().count(), 1, "expected single-line stderr: {err}");
|
|
assert!(err.contains("bad_map.tsv:2:"), "{err}");
|
|
assert!(!out1.join("bars_1d").exists());
|
|
|
|
// 2. Truncated BSON -> single-line stderr naming path, no bars_1d.
|
|
let trunc_eod = dir.path.join("trunc.bson");
|
|
let mut doc = make_eod_doc("NVDA.US", "2024-06-07", 100.0, 1000.0);
|
|
doc.truncate(doc.len() - 4);
|
|
write_file(&trunc_eod, &doc);
|
|
let out2 = dir.path.join("out2");
|
|
let res2 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
trunc_eod.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_ok.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out2.to_str().unwrap(),
|
|
]);
|
|
assert!(!res2.status.success());
|
|
assert!(stdout(&res2).is_empty());
|
|
let err2 = stderr(&res2);
|
|
assert_eq!(err2.lines().count(), 1, "expected single-line stderr: {err2}");
|
|
assert!(err2.contains("trunc.bson"), "{err2}");
|
|
assert!(!out2.join("bars_1d").exists());
|
|
|
|
// 3. Missing input file -> single-line stderr naming path, no bars_1d.
|
|
let missing_eod = dir.path.join("missing_eod.bson");
|
|
let out3 = dir.path.join("out3");
|
|
let res3 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
missing_eod.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_ok.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out3.to_str().unwrap(),
|
|
]);
|
|
assert!(!res3.status.success());
|
|
assert!(stdout(&res3).is_empty());
|
|
let err3 = stderr(&res3);
|
|
assert_eq!(err3.lines().count(), 1, "expected single-line stderr: {err3}");
|
|
assert!(err3.contains("missing_eod.bson"), "{err3}");
|
|
assert!(!out3.join("bars_1d").exists());
|
|
|
|
// 4. Oversized BSON document (> DEFAULT_MAX_DOC_BYTES) -> single-line stderr naming path, no bars_1d.
|
|
let huge_eod = dir.path.join("huge_eod.bson");
|
|
let huge_len = (curate_etl::bson_stream::DEFAULT_MAX_DOC_BYTES as i32) + 1024;
|
|
let mut huge_bytes = Vec::from(huge_len.to_le_bytes());
|
|
huge_bytes.push(0);
|
|
write_file(&huge_eod, &huge_bytes);
|
|
let out4 = dir.path.join("out4");
|
|
let res4 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
huge_eod.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_ok.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out4.to_str().unwrap(),
|
|
]);
|
|
assert!(!res4.status.success());
|
|
assert!(stdout(&res4).is_empty());
|
|
let err4 = stderr(&res4);
|
|
assert_eq!(err4.lines().count(), 1, "expected single-line stderr: {err4}");
|
|
assert!(err4.contains("huge_eod.bson"), "{err4}");
|
|
assert!(!out4.join("bars_1d").exists());
|
|
|
|
// 5. Overlapping mapping ranges -> single-line stderr naming path, no bars_1d.
|
|
let overlap_map = dir.path.join("overlap_map.tsv");
|
|
write_file(
|
|
&overlap_map,
|
|
b"eod\tNVDA.US\t2020-01-01\t2022-12-31\t1\neod\tNVDA.US\t2022-06-01\t2024-12-31\t2\n",
|
|
);
|
|
let out5 = dir.path.join("out5");
|
|
let res5 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_ok.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
overlap_map.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out5.to_str().unwrap(),
|
|
]);
|
|
assert!(!res5.status.success());
|
|
assert!(stdout(&res5).is_empty());
|
|
let err5 = stderr(&res5);
|
|
assert_eq!(err5.lines().count(), 1, "expected single-line stderr: {err5}");
|
|
assert!(err5.contains("overlap_map.tsv"), "{err5}");
|
|
assert!(!out5.join("bars_1d").exists());
|
|
|
|
// 6. Conflicting cross-key QM alias splits -> single-line stderr naming path, no bars_1d.
|
|
let alias_map = dir.path.join("alias_map.tsv");
|
|
write_file(
|
|
&alias_map,
|
|
b"eod\tNVDA.US\t2020-01-01\t\t1\nqm\tNVDA:US\t2020-01-01\t\t1\nqm\tNVDA_ALT:US\t2020-01-01\t\t1\n",
|
|
);
|
|
let conflict_splits = dir.path.join("conflict_splits.bson");
|
|
let c1 = make_split_doc("NVDA:US", "2024-06-10", 10.0);
|
|
let c2 = make_split_doc("NVDA_ALT:US", "2024-06-10", 4.0);
|
|
write_file(&conflict_splits, &[c1.as_slice(), c2.as_slice()].concat());
|
|
let out6 = dir.path.join("out6");
|
|
let res6 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_ok.to_str().unwrap(),
|
|
"--qm-splits",
|
|
conflict_splits.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
alias_map.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out6.to_str().unwrap(),
|
|
]);
|
|
assert!(!res6.status.success());
|
|
assert!(stdout(&res6).is_empty());
|
|
let err6 = stderr(&res6);
|
|
assert_eq!(err6.lines().count(), 1, "expected single-line stderr: {err6}");
|
|
assert!(err6.contains("conflict_splits.bson"), "{err6}");
|
|
assert!(!out6.join("bars_1d").exists());
|
|
|
|
// 7. Output write failure reaching the Parquet writer: `--out` is a valid directory, but
|
|
// `<out>/bars_1d` is occupied by a regular file.
|
|
let out7 = dir.path.join("out7_obstructed");
|
|
fs::create_dir_all(&out7).expect("create out7 dir");
|
|
let bars_1d_file = out7.join("bars_1d");
|
|
write_file(&bars_1d_file, b"sentinel");
|
|
let res7 = run(&[
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_ok.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_ok.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
out7.to_str().unwrap(),
|
|
]);
|
|
assert!(!res7.status.success());
|
|
assert!(stdout(&res7).is_empty());
|
|
let err7 = stderr(&res7);
|
|
assert_eq!(err7.lines().count(), 1, "expected single-line stderr: {err7}");
|
|
assert!(err7.contains("out7_obstructed"), "{err7}");
|
|
assert!(bars_1d_file.is_file());
|
|
assert_eq!(fs::read(&bars_1d_file).unwrap(), b"sentinel");
|
|
assert!(!out7.join("bars_1d/year=2024/part.parquet").exists());
|
|
}
|
|
|
|
#[test]
|
|
fn curate_bars_1d_cli_rejects_following_option_token_as_out_value_without_writing() {
|
|
let dir = CliTempDir::new("missing-out-opt");
|
|
let eod_ok = dir.path.join("eod.bson");
|
|
let splits_ok = dir.path.join("splits.bson");
|
|
let map_ok = dir.path.join("map.tsv");
|
|
let curr_ok = dir.path.join("curr.tsv");
|
|
write_file(&eod_ok, &make_eod_doc("NVDA.US", "2024-06-07", 100.0, 1000.0));
|
|
write_file(&splits_ok, b"");
|
|
write_file(&map_ok, b"eod\tNVDA.US\t2020-01-01\t\t1\n");
|
|
write_file(&curr_ok, b"1\tUSD\n");
|
|
|
|
let res = Command::new(env!("CARGO_BIN_EXE_curate-etl"))
|
|
.current_dir(&dir.path)
|
|
.args([
|
|
"curate-bars-1d",
|
|
"--eod-prices",
|
|
eod_ok.to_str().unwrap(),
|
|
"--qm-splits",
|
|
splits_ok.to_str().unwrap(),
|
|
"--provider-mapping",
|
|
map_ok.to_str().unwrap(),
|
|
"--listing-currencies",
|
|
curr_ok.to_str().unwrap(),
|
|
"--out",
|
|
"--rel-tolerence=0.01",
|
|
])
|
|
.output()
|
|
.expect("spawn curate-etl binary");
|
|
|
|
assert!(!res.status.success());
|
|
assert_eq!(res.status.code(), Some(1));
|
|
assert!(stdout(&res).is_empty());
|
|
let err = stderr(&res);
|
|
assert!(err.contains("missing value for flag '--out'"), "{err}");
|
|
assert!(err.contains("Usage:"), "{err}");
|
|
assert!(
|
|
!dir.path.join("--rel-tolerence=0.01").exists(),
|
|
"must not create output directory named after following option token"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn bench_curate_bars_cmd_small_run_succeeds_and_reports_splits() {
|
|
let out = run(&["bench-curate-bars-cmd", "2000"]);
|
|
assert!(out.status.success(), "{}", stderr(&out));
|
|
assert!(stderr(&out).is_empty(), "{}", stderr(&out));
|
|
let text = stdout(&out);
|
|
assert!(text.contains("curate-etl bench-curate-bars-cmd"), "{text}");
|
|
assert!(text.contains("rows=2000 "), "{text}");
|
|
assert!(text.contains("decode:"), "{text}");
|
|
assert!(text.contains("curate:"), "{text}");
|
|
assert!(text.contains("write:"), "{text}");
|
|
assert!(text.contains("total:"), "{text}");
|
|
assert!(text.contains("bytes/bar"), "{text}");
|
|
}
|