T-187: tests
This commit is contained in:
parent
16f9132e84
commit
8f3f802cc0
1 changed files with 141 additions and 0 deletions
|
|
@ -1585,3 +1585,144 @@ fn error_display_is_single_line_and_names_paths() {
|
|||
assert!(errs[5].to_string().contains("/i/x.bson"));
|
||||
assert!(errs[6].to_string().contains("/o/tmp"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// QA: CLI wiring parity (T-187)
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
fn run_via_cli(argv: &[&str]) -> CurateFx1mRunReport {
|
||||
let args: Vec<String> = argv.iter().map(|s| (*s).to_string()).collect();
|
||||
match crate::cli::parse_args(&args).expect("curate-fx-1m argv should parse") {
|
||||
crate::cli::CliAction::CurateFx1m(parsed) => {
|
||||
run_curate_fx_1m(&parsed).expect("CLI-parsed run should succeed")
|
||||
}
|
||||
other => panic!("expected CliAction::CurateFx1m, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_reports_equal_ignoring_elapsed(a: &CurateFx1mRunReport, b: &CurateFx1mRunReport) {
|
||||
assert_eq!(a.decode, b.decode);
|
||||
assert_eq!(a.curate_stats, b.curate_stats);
|
||||
assert_eq!(a.rows_written, b.rows_written);
|
||||
assert_eq!(a.ilp_stats, b.ilp_stats);
|
||||
assert_eq!(a.shard_count, b.shard_count);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_parsed_curate_fx_1m_matches_direct_runner_bytes_and_counters() {
|
||||
let dir = TempDirGuard::new("fx1m-qa-cli-parity");
|
||||
let ts1 = 1_718_700_000_i64; // 2024-06-18 08:40:00 UTC
|
||||
let ts2 = ts1 + 60;
|
||||
let intraday_path = dir.path().join("eodIntraday1M.bson");
|
||||
fs::write(
|
||||
&intraday_path,
|
||||
concat_docs(&[
|
||||
make_intraday_doc(EOD_CAD_FOREX_CODE, ts2, 1.3705, 1.3715, 1.37, 1.371, 0.0),
|
||||
make_intraday_doc("AAPL.US", ts1, 195.0, 196.0, 194.5, 195.5, 1000.0),
|
||||
make_intraday_doc(EOD_CAD_FOREX_CODE, ts1, 1.37, 1.371, 1.369, 1.3705, 0.0),
|
||||
// Bitwise-identical duplicate collapses.
|
||||
make_intraday_doc(EOD_CAD_FOREX_CODE, ts1, 1.37, 1.371, 1.369, 1.3705, 0.0),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
let intraday = intraday_path.to_str().unwrap().to_string();
|
||||
|
||||
// Reference: runner with hand-built args and default options.
|
||||
let direct_out = dir.path().join("direct");
|
||||
let direct = run_curate_fx_1m(&make_args(
|
||||
intraday_path.clone(),
|
||||
direct_out.clone(),
|
||||
4,
|
||||
BsonStreamOptions::default(),
|
||||
))
|
||||
.expect("direct run succeeds");
|
||||
assert_eq!(direct.rows_written, 2);
|
||||
assert_eq!(direct.curate_stats.dropped_wrong_code, 1);
|
||||
|
||||
// CLI space form.
|
||||
let space_out = dir.path().join("cli-space");
|
||||
let space_out_s = space_out.to_str().unwrap().to_string();
|
||||
let via_space = run_via_cli(&[
|
||||
"curate-fx-1m",
|
||||
"--eod-intraday",
|
||||
&intraday,
|
||||
"--out",
|
||||
&space_out_s,
|
||||
"--shards",
|
||||
"4",
|
||||
]);
|
||||
|
||||
// CLI equals form, flags reordered.
|
||||
let eq_out = dir.path().join("cli-eq");
|
||||
let shards_tok = "--shards=4".to_string();
|
||||
let out_tok = format!("--out={}", eq_out.to_str().unwrap());
|
||||
let intraday_tok = format!("--eod-intraday={intraday}");
|
||||
let via_eq = run_via_cli(&["curate-fx-1m", &shards_tok, &out_tok, &intraday_tok]);
|
||||
|
||||
assert_reports_equal_ignoring_elapsed(&via_space, &direct);
|
||||
assert_reports_equal_ignoring_elapsed(&via_eq, &direct);
|
||||
|
||||
let expected_names: Vec<String> = (0..4).map(|i| format!("fx_1m.shard-{i:02}.ilp")).collect();
|
||||
let direct_snapshot = snapshot_dir(&direct_out);
|
||||
assert_eq!(
|
||||
direct_snapshot
|
||||
.iter()
|
||||
.map(|(n, _)| n.clone())
|
||||
.collect::<Vec<_>>(),
|
||||
expected_names
|
||||
);
|
||||
assert_eq!(snapshot_dir(&space_out), direct_snapshot);
|
||||
assert_eq!(snapshot_dir(&eq_out), direct_snapshot);
|
||||
|
||||
// Exactly one populated shard carrying USDCAD/eod rows at UTC bar-start micros.
|
||||
let rows: Vec<DecodedIlpFx1m> = direct_snapshot
|
||||
.iter()
|
||||
.flat_map(|(_, bytes)| decode_ilp_fx_1m(bytes))
|
||||
.collect();
|
||||
let populated = direct_snapshot
|
||||
.iter()
|
||||
.filter(|(_, b)| !b.is_empty())
|
||||
.count();
|
||||
assert_eq!(populated, 1);
|
||||
assert_eq!(
|
||||
rows.iter().map(|r| r.ts).collect::<Vec<_>>(),
|
||||
vec![ts1 * 1_000_000, ts2 * 1_000_000]
|
||||
);
|
||||
for row in &rows {
|
||||
assert_eq!(row.pair, FX_PAIR_USDCAD);
|
||||
assert_eq!(row.source, FX_1M_SOURCE_EOD);
|
||||
}
|
||||
assert_eq!(rows[0].close.to_bits(), 1.3705_f64.to_bits());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_parsed_curate_fx_1m_missing_input_fails_without_publishing_shards() {
|
||||
let dir = TempDirGuard::new("fx1m-qa-cli-missing");
|
||||
let missing = dir.path().join("does-not-exist.bson");
|
||||
let out_dir = dir.path().join("out");
|
||||
let args: Vec<String> = [
|
||||
"curate-fx-1m",
|
||||
"--eod-intraday",
|
||||
missing.to_str().unwrap(),
|
||||
"--out",
|
||||
out_dir.to_str().unwrap(),
|
||||
"--shards",
|
||||
"2",
|
||||
]
|
||||
.iter()
|
||||
.map(|s| (*s).to_string())
|
||||
.collect();
|
||||
let crate::cli::CliAction::CurateFx1m(parsed) = crate::cli::parse_args(&args).unwrap() else {
|
||||
panic!("expected CliAction::CurateFx1m");
|
||||
};
|
||||
let err = run_curate_fx_1m(&parsed).unwrap_err();
|
||||
assert!(err.to_string().contains("does-not-exist.bson"), "{err}");
|
||||
let leftover: Vec<String> = list_dir_names(&out_dir)
|
||||
.into_iter()
|
||||
.filter(|n| n.starts_with("fx_1m."))
|
||||
.collect();
|
||||
assert!(
|
||||
leftover.is_empty(),
|
||||
"no shard output expected: {leftover:?}"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue