()
| 332 | #[test] |
| 333 | #[ignore] |
| 334 | fn fuzz_test_timed() { |
| 335 | // Parse time duration from environment variable or default to 10 seconds |
| 336 | let duration_str = env::var("FUZZ_TIME").unwrap_or_else(|_| "10s".to_string()); |
| 337 | let duration = parse_duration(&duration_str).unwrap_or(Duration::from_secs(10)); |
| 338 | |
| 339 | println!("Running timed fuzz test for {:?}", duration); |
| 340 | |
| 341 | let start_time = Instant::now(); |
| 342 | let mut total_operations = 0; |
| 343 | let mut total_keys_inserted = 0; |
| 344 | let mut max_nodes_reached = 0; |
| 345 | |
| 346 | while start_time.elapsed() < duration { |
| 347 | // Cycle through different branching factors |
| 348 | for branching_factor in [4, 5, 7, 8, 10] { |
| 349 | if start_time.elapsed() >= duration { |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | let mut bplustree = BPlusTreeMap::new(branching_factor).unwrap(); |
| 354 | let mut btree_map = BTreeMap::new(); |
| 355 | let mut operations = Vec::new(); |
| 356 | |
| 357 | // Run until we hit time limit or reach a reasonable number of nodes |
| 358 | let mut key = 1; |
| 359 | while start_time.elapsed() < duration && bplustree.leaf_count() < 50 { |
| 360 | let value = key * 10; |
| 361 | |
| 362 | // Record the operation |
| 363 | operations.push(format!("insert({}, {})", key, value)); |
| 364 | total_operations += 1; |
| 365 | |
| 366 | // Insert into both trees |
| 367 | let bplus_result = bplustree.insert(key, value); |
| 368 | let btree_result = btree_map.insert(key, value); |
| 369 | |
| 370 | // Check that insert results match |
| 371 | if bplus_result != btree_result { |
| 372 | println!( |
| 373 | "MISMATCH on insert({}, {}) with branching factor {}:", |
| 374 | key, value, branching_factor |
| 375 | ); |
| 376 | println!("BPlusTree returned: {:?}", bplus_result); |
| 377 | println!("BTreeMap returned: {:?}", btree_result); |
| 378 | println!("Recent operations:"); |
| 379 | for op in operations.iter().rev().take(10) { |
| 380 | println!(" {}", op); |
| 381 | } |
| 382 | panic!("Insert result mismatch!"); |
| 383 | } |
| 384 | |
| 385 | // Periodically verify all keys can be found |
| 386 | if key % 10 == 0 { |
| 387 | for check_key in 1..=key { |
| 388 | let bplus_value = bplustree.get(&check_key); |
| 389 | let btree_value = btree_map.get(&check_key); |
| 390 | |
| 391 | if bplus_value != btree_value { |
nothing calls this directly
no test coverage detected