From 51593c44ec9d722dbba1e3b659946f64a3eaed66 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:15:16 +0000 Subject: [PATCH 1/2] Add tests for ScriptMutex::lock Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/sync.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stdlib/src/sync.rs b/stdlib/src/sync.rs index bdb50b9e..f0250e3f 100644 --- a/stdlib/src/sync.rs +++ b/stdlib/src/sync.rs @@ -125,4 +125,26 @@ mod tests { let guard = mutex.locked.lock().unwrap(); assert_eq!(*guard, false); } + + #[test] + fn test_script_mutex_lock() { + use std::sync::Arc; + use std::thread; + use std::time::Duration; + + let mutex = Arc::new(ScriptMutex::new()); + let mutex_clone = Arc::clone(&mutex); + + mutex.lock(); + + let handle = thread::spawn(move || { + mutex_clone.lock(); + mutex_clone.unlock(); + }); + + thread::sleep(Duration::from_millis(50)); + mutex.unlock(); + + handle.join().unwrap(); + } } From cf2ad661882893bfeb94d78cd9e2cf2732cf08ae Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 13:25:47 +0000 Subject: [PATCH 2/2] Add robust tests for ScriptMutex::lock Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/sync.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stdlib/src/sync.rs b/stdlib/src/sync.rs index f0250e3f..b21c911f 100644 --- a/stdlib/src/sync.rs +++ b/stdlib/src/sync.rs @@ -131,20 +131,29 @@ mod tests { use std::sync::Arc; use std::thread; use std::time::Duration; + use std::sync::atomic::{AtomicBool, Ordering}; let mutex = Arc::new(ScriptMutex::new()); let mutex_clone = Arc::clone(&mutex); + let flag = Arc::new(AtomicBool::new(false)); + let flag_clone = Arc::clone(&flag); mutex.lock(); let handle = thread::spawn(move || { mutex_clone.lock(); + flag_clone.store(true, Ordering::SeqCst); mutex_clone.unlock(); }); thread::sleep(Duration::from_millis(50)); + // Verify the second thread is blocked and hasn't set the flag + assert_eq!(flag.load(Ordering::SeqCst), false); + mutex.unlock(); handle.join().unwrap(); + // Verify the second thread acquired the lock and set the flag + assert_eq!(flag.load(Ordering::SeqCst), true); } }