From 9f79e792c541a0701a5e0a09e05cf651ba9dd003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gonz=C3=A1lez?= Date: Fri, 29 Mar 2024 10:43:09 +0100 Subject: [PATCH] fix(test_utils): recover from lock poisoning in tests (#18) Small fix so that when a test thread panics (which happens when an `assert_eq` evaluates to `false`), we recover from it and all other tests continue running. Otherwise, the lock gets poisoned, we `unwrap` and all the other tests fail. --- contracts/src/test_utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/test_utils.rs b/contracts/src/test_utils.rs index b37d405e..24ea6d39 100644 --- a/contracts/src/test_utils.rs +++ b/contracts/src/test_utils.rs @@ -14,7 +14,7 @@ pub(crate) static STORAGE_MUTEX: Mutex<()> = Mutex::new(()); /// Acquires access to storage. pub(crate) fn acquire_storage() -> MutexGuard<'static, ()> { - STORAGE_MUTEX.lock().unwrap() + STORAGE_MUTEX.lock().unwrap_or_else(|e| e.into_inner()) } /// Decorates a closure by running it with exclusive access to storage.