From fcbb2722f17839ea752397fb5eede333a46c58e6 Mon Sep 17 00:00:00 2001 From: MultisampledNight Date: Sat, 30 Apr 2022 16:11:23 +0200 Subject: [PATCH] Fix deadlock in test The test held a read lock on SETTINGS while trying to write to it. As both happened on the same thread, that went wrong and caused a deadlock. --- src/settings/mod.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 21cf4fb..8402f6f 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -194,20 +194,25 @@ mod tests { let vt2 = TypeId::of::(); let v3: u32 = 2; - settings.set(&v1); - let values = settings.settings.read(); - let r1 = values.get(&vt1).unwrap().downcast_ref::().unwrap(); - assert_eq!(v1, *r1); + { + settings.set(&v1); - settings.set(&v2); + let values = settings.settings.read(); + let r1 = values.get(&vt1).unwrap().downcast_ref::().unwrap(); + assert_eq!(v1, *r1); + } - settings.set(&v3); + { + settings.set(&v2); + settings.set(&v3); - let r2 = values.get(&vt1).unwrap().downcast_ref::().unwrap(); - let r3 = values.get(&vt2).unwrap().downcast_ref::().unwrap(); + let values = settings.settings.read(); + let r2 = values.get(&vt1).unwrap().downcast_ref::().unwrap(); + let r3 = values.get(&vt2).unwrap().downcast_ref::().unwrap(); - assert_eq!(v3, *r2); - assert_eq!(v2, *r3); + assert_eq!(v3, *r2); + assert_eq!(v2, *r3); + } } #[test]