/* Copyright 2018-2019 Mozilla Foundation * *LicensedundertheApacheLicense(Version2.0),ortheMITlicense, *(the"Licenses")atyouroption.Youmaynotusethisfileexceptin *compliancewithoneoftheLicenses.Youmayobtaincopiesofthe *Licensesat: * *http://www.apache.org/licenses/LICENSE-2.0 *http://opensource.org/licenses/MIT * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicensesisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicensesforthespecificlanguagegoverningpermissionsand *limitationsundertheLicenses.
*/
//! This test is a stress test meant to trigger some bugs seen prior to the use //! of handlemaps. See /docs/design/test-faster.md for why it's split -- TLDR: //! it uses rayon and is hard to rewrite with normal threads.
use ffi_support::{ConcurrentHandleMap, ExternError}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc;
fn with_error<F: FnOnce(&mut ExternError) -> T, T>(callback: F) -> T { letmut e = ExternError::success(); let result = callback(&mut e); iflet Some(m) = unsafe { e.get_and_consume_message() } {
panic!("unexpected error: {}", m);
}
result
}
struct DropChecking {
counter: Arc<AtomicUsize>,
id: usize,
} impl Drop for DropChecking { fn drop(&mutself) { let val = self.counter.fetch_add(1, Ordering::SeqCst);
log::debug!("Dropped {} :: {}", self.id, val);
}
} #[test] fn test_concurrent_drop() { use rand::prelude::*; use rayon::prelude::*; let _ = env_logger::try_init(); let drop_counter = Arc::new(AtomicUsize::new(0)); let id = Arc::new(AtomicUsize::new(1)); let map = ConcurrentHandleMap::new(); let count = 1000; letmut handles = (0..count)
.into_par_iter()
.map(|_| { let id = id.fetch_add(1, Ordering::SeqCst); let handle = with_error(|e| {
map.insert_with_output(e, || {
log::debug!("Created {}", id);
DropChecking {
counter: drop_counter.clone(),
id,
}
})
});
(id, handle)
})
.collect::<Vec<_>>();
handles.par_iter().for_each(|(id, h)| { let item = map
.remove_u64(*h)
.expect("remove to succeed")
.expect("item to exist");
assert_eq!(item.id, *id); let h = map.insert(item).into_u64();
map.delete_u64(h).expect("delete to succeed");
});
assert_eq!(drop_counter.load(Ordering::SeqCst), count);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.