| 351 | |
| 352 | #[test] |
| 353 | fn flush_threshold_ops() { |
| 354 | let reg = SurrogateRegistry::new(); |
| 355 | assert!(!reg.should_flush(), "fresh registry should not flush yet"); |
| 356 | for _ in 0..(FLUSH_OPS_THRESHOLD - 1) { |
| 357 | let _ = reg.alloc_one().unwrap(); |
| 358 | } |
| 359 | assert!(!reg.should_flush(), "below ops threshold should not flush"); |
| 360 | let _ = reg.alloc_one().unwrap(); |
| 361 | assert!(reg.should_flush(), "at ops threshold should flush"); |
| 362 | |
| 363 | let persist = MemPersist::new(); |
| 364 | reg.flush(&persist).unwrap(); |
| 365 | assert_eq!(persist.calls(), 1); |
| 366 | assert_eq!(persist.last(), Some(FLUSH_OPS_THRESHOLD as u32)); |
| 367 | assert!(!reg.should_flush(), "post-flush should clear ops"); |
| 368 | } |
| 369 | |
| 370 | #[test] |
| 371 | fn flush_threshold_elapsed() { |