From ead29a08c0cf066b6c5bda8a474d62c9f9648b1c 2022-01-07 11:15:57 From: mh Date: 2022-01-07 11:15:57 Subject: [PATCH] WIP: Adding ctor/dtor tests to MPSC queue --- diff --git a/src/runtime2/store/component.rs b/src/runtime2/store/component.rs index d93245908fd4587e882f148afe5db432006579bd..58de8ce520ba17e2f8b6a1293226bf4a55e0d2e1 100644 --- a/src/runtime2/store/component.rs +++ b/src/runtime2/store/component.rs @@ -336,6 +336,7 @@ impl Drop for ComponentStore { #[cfg(test)] mod tests { use super::*; + use crate::runtime2::store::tests::Resource; use rand::prelude::*; use rand_pcg::Pcg32; @@ -343,24 +344,6 @@ mod tests { use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; - pub struct Resource { - dtor: Arc, - val: u64, - } - - impl Resource { - fn new(ctor: Arc, dtor: Arc, val: u64) -> Self { - ctor.fetch_add(1, Ordering::SeqCst); - return Self{ dtor, val }; - } - } - - impl Drop for Resource { - fn drop(&mut self) { - self.dtor.fetch_add(1, Ordering::SeqCst); - } - } - fn seeds() -> Vec<[u8;16]> { return vec![ [241, 47, 70, 87, 240, 246, 20, 173, 219, 143, 74, 23, 158, 58, 205, 172], diff --git a/src/runtime2/store/mod.rs b/src/runtime2/store/mod.rs index f5ee1f0a39c16b8dfb05cd55cc8a62d5f85e0abd..2280851592f0825f9e3a253f27090f01eb44c38d 100644 --- a/src/runtime2/store/mod.rs +++ b/src/runtime2/store/mod.rs @@ -3,3 +3,29 @@ pub mod unfair_se_lock; pub mod queue_mpsc; pub(crate) use component::ComponentStore; + +#[cfg(test)] +mod tests { + use std::sync::Arc; + use std::sync::atomic::{AtomicU64, Ordering}; + + // Utility resource structure that counts the number of constructors and + // destructor calls. + pub struct Resource { + dtor: Arc, + val: u64, + } + + impl Resource { + fn new(ctor: Arc, dtor: Arc, val: u64) -> Self { + ctor.fetch_add(1, Ordering::SeqCst); + return Self{ dtor, val }; + } + } + + impl Drop for Resource { + fn drop(&mut self) { + self.dtor.fetch_add(1, Ordering::SeqCst); + } + } +} \ No newline at end of file