mirror of
https://github.com/penpot/penpot.git
synced 2026-09-12 06:58:57 +00:00
🔧 Use mutex so only one test owns global at a time (#11585)
This commit is contained in:
parent
d45c6710b7
commit
3d4a5ca2aa
@ -124,14 +124,21 @@ macro_rules! with_current_shape {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) struct TestRenderResourcesGuard {
|
pub(crate) struct TestRenderResourcesGuard {
|
||||||
prev: *mut RenderResources,
|
prev: *mut RenderResources,
|
||||||
|
_lock: std::sync::MutexGuard<'static, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
static TEST_RENDER_RESOURCES_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
impl TestRenderResourcesGuard {
|
impl TestRenderResourcesGuard {
|
||||||
pub(crate) fn install(resources: &mut RenderResources) -> Self {
|
pub(crate) fn install(resources: &mut RenderResources) -> Self {
|
||||||
|
let lock = TEST_RENDER_RESOURCES_LOCK
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||||
let prev = unsafe { RENDER_RESOURCES };
|
let prev = unsafe { RENDER_RESOURCES };
|
||||||
unsafe { RENDER_RESOURCES = resources as *mut _ };
|
unsafe { RENDER_RESOURCES = resources as *mut _ };
|
||||||
Self { prev }
|
Self { prev, _lock: lock }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user