//! This module contains property-based tests against the public API: //! * API never panics. //! * Active entries cannot be overridden until removed. //! * The slab doesn't produce overlapping keys. //! * The slab doesn't leave "lost" keys. //! * `get()`, `get_owned`, and `contains()` are consistent. //! * `RESERVED_BITS` are actually not used. //! //! The test is supposed to be deterministic, so it doesn't spawn real threads //! and uses `tid::with()` to override the TID for the current thread.
/// Stores active entries (added and not yet removed). #[derive(Default)] struct Active { // Use `IndexMap` to preserve determinism.
map: IndexMap<usize, u32>,
prev_value: u32,
}
// Apply all actions. for action in actions { // Override the TID for the current thread instead of using multiple real threads // to preserve determinism. We're not checking concurrency issues here, they should be // covered by loom tests anyway. Thus, it's fine to run all actions consequently.
tid::with(action.tid, || {
apply_action::<C>(&slab, &mut active, action.kind)
})?;
}
// Ensure the slab contains all remaining entries. letmut expected_values = Vec::new(); for (key, value) in active.drain() {
prop_assert!(slab.contains(key));
prop_assert_eq!(slab.get(key).map(|e| *e), Some(value));
prop_assert_eq!(slab.clone().get_owned(key).map(|e| *e), Some(value));
expected_values.push(value);
}
expected_values.sort();
// Ensure `unique_iter()` returns all remaining entries. let slab = Arc::get_mut(&mut slab).unwrap(); letmut actual_values = slab.unique_iter().copied().collect::<Vec<_>>();
actual_values.sort();
prop_assert_eq!(actual_values, expected_values);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.