use std::path::PathBuf;
use std::sync::Arc;
use html_to_markdown_rs::{ConversionOptions, TierStrategy, convert};
const THREAD_COUNT: usize = 64;
const FIXTURE_NAMES: &[&str] = &[
"small_html.html",
"lists_timeline.html",
"medium_python.html",
"tables_countries.html",
];
fn fixtures_dir() -> PathBuf {
let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace_root = manifest
.parent() .and_then(|p| p.parent()) .expect("could not resolve workspace root from CARGO_MANIFEST_DIR")
.to_path_buf();
workspace_root.join("tools/benchmark-harness/fixtures/real-world/wikipedia")
}
fn default_opts() -> ConversionOptions {
ConversionOptions {
tier_strategy: TierStrategy::Auto,
extract_metadata: false,
..ConversionOptions::default()
}
}
fn load_fixtures() -> Vec<(String, String)> {
let dir = fixtures_dir();
let mut result = Vec::new();
for name in FIXTURE_NAMES {
let path = dir.join(name);
let html =
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read fixture {}: {e}", path.display()));
let reference = convert(&html, Some(default_opts()))
.unwrap_or_else(|e| panic!("serial convert failed for {name}: {e}"))
.content
.unwrap_or_default();
result.push((html, reference));
}
result
}
#[test]
fn all_threads_produce_output_equal_to_serial_reference() {
let fixtures = Arc::new(load_fixtures());
let handles: Vec<_> = (0..THREAD_COUNT)
.map(|i| {
let fixtures = Arc::clone(&fixtures);
std::thread::spawn(move || {
let (html, reference) = &fixtures[i % fixtures.len()];
let output = convert(html, Some(default_opts()))
.unwrap_or_else(|e| panic!("thread {i} convert failed: {e}"))
.content
.unwrap_or_default();
assert_eq!(
output,
*reference,
"thread {i} output differed from serial reference (fixture index {fi})",
fi = i % fixtures.len()
);
})
})
.collect();
for handle in handles {
handle.join().unwrap_or_else(|e| {
std::panic::resume_unwind(e);
});
}
}
#[test]
fn thread_count_and_fixture_count_are_as_expected() {
assert_eq!(THREAD_COUNT, 64, "thread count must be 64");
assert_eq!(FIXTURE_NAMES.len(), 4, "fixture count must be 4");
}