use std::time::Instant;
use tensor_wasm_artifacts::{ArtifactStore, DiskArtifactStore, MAX_PAYLOAD_LEN};
const PAYLOAD_LEN: usize = 100 * 1024 * 1024;
#[test]
#[ignore = "100 MiB round-trip; run with `cargo test -p tensor-wasm-artifacts -- --ignored streaming_perf`"]
fn streaming_put_get_100_mib_round_trip() {
const _: () = assert!(
PAYLOAD_LEN < MAX_PAYLOAD_LEN,
"test payload must stay below put cap",
);
let payload: Vec<u8> = (0..PAYLOAD_LEN).map(|i| (i & 0xFF) as u8).collect();
let tmp = tempfile::tempdir().expect("tempdir");
let store = DiskArtifactStore::new(tmp.path().to_path_buf(), [0x7Bu8; 32]);
let put_start = Instant::now();
let hash = store.put(&payload).expect("put 100 MiB");
let put_elapsed = put_start.elapsed();
let get_start = Instant::now();
let got = store.get(&hash).expect("get 100 MiB");
let get_elapsed = get_start.elapsed();
assert_eq!(got.len(), payload.len(), "round-trip length matches");
assert_eq!(got[0], payload[0]);
assert_eq!(got[PAYLOAD_LEN / 2], payload[PAYLOAD_LEN / 2]);
assert_eq!(got[PAYLOAD_LEN - 1], payload[PAYLOAD_LEN - 1]);
eprintln!(
"streaming_perf: put 100 MiB in {:?}, get 100 MiB in {:?}",
put_elapsed, get_elapsed
);
assert!(
put_elapsed.as_secs() < 60,
"put took {put_elapsed:?}; likely regression"
);
assert!(
get_elapsed.as_secs() < 60,
"get took {get_elapsed:?}; likely regression"
);
}
#[test]
#[ignore = "exercises put at the size cap; run with `cargo test -p tensor-wasm-artifacts -- --ignored streaming_perf`"]
fn streaming_put_at_cap_boundary_succeeds() {
let payload: Vec<u8> = (0..MAX_PAYLOAD_LEN).map(|i| (i & 0xFF) as u8).collect();
let tmp = tempfile::tempdir().expect("tempdir");
let store = DiskArtifactStore::new(tmp.path().to_path_buf(), [0x42u8; 32]);
let hash = store.put(&payload).expect("put at cap must succeed");
drop(payload);
let got = store.get(&hash).expect("get at cap must succeed");
assert_eq!(got.len(), MAX_PAYLOAD_LEN);
assert_eq!(got[0], 0);
assert_eq!(
got[MAX_PAYLOAD_LEN - 1],
((MAX_PAYLOAD_LEN - 1) & 0xFF) as u8
);
}