Skip to content

Commit

Permalink
chore: Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Apr 21, 2022
1 parent d4b221e commit 04004ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `NamedLock::create` now rejects names that contain `/` or `\` characters (#2, #4)
- `NamedLock::create` on Windows explicitly creates a global mutex
- `Error::CreateFailed` now has the source of the error
- Upgrade all dependencies
15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ keywords = ["process", "inter-process", "cross-process", "flock", "CreateMutexW"
repository = "https://github.com/oblique/named-lock"

[dependencies]
thiserror = "1"
once_cell = "1.3"
parking_lot = "0.10"
thiserror = "1.0.30"
once_cell = "1.10.0"
parking_lot = "0.12.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2.66"
libc = "0.2.124"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["handleapi", "synchapi", "winbase", "winnt", "winerror"] }
widestring = "0.4"
winapi = { version = "0.3.9", features = ["handleapi", "synchapi", "winbase", "winnt", "winerror"] }
widestring = "0.5.1"

[dev-dependencies]
matches = "0.1"
uuid = { version = "0.8", features = ["v4"] }
uuid = { version = "1.0.0", features = ["v4"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
19 changes: 9 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ impl<'r> Drop for NamedLockGuard<'r> {
#[cfg(test)]
mod tests {
use super::*;
use matches::assert_matches;
use std::env;
use std::process::{Child, Command};
use std::thread::sleep;
Expand All @@ -202,7 +201,7 @@ mod tests {
.and_then(|v| v.parse().ok())
.unwrap_or(0);
let uuid = env::var("TEST_CROSS_PROCESS_LOCK_UUID")
.unwrap_or_else(|_| Uuid::new_v4().to_hyphenated().to_string());
.unwrap_or_else(|_| Uuid::new_v4().as_hyphenated().to_string());

match proc_num {
0 => {
Expand All @@ -213,7 +212,7 @@ mod tests {
sleep(Duration::from_millis(200));

let lock = NamedLock::create(&uuid)?;
assert_matches!(lock.try_lock(), Err(Error::WouldBlock));
assert!(matches!(lock.try_lock(), Err(Error::WouldBlock)));
lock.lock().expect("failed to lock");

assert!(handle2.wait().unwrap().success());
Expand All @@ -224,14 +223,14 @@ mod tests {
NamedLock::create(&uuid).expect("failed to create lock");

let _guard = lock.lock().expect("failed to lock");
assert_matches!(lock.try_lock(), Err(Error::WouldBlock));
assert!(matches!(lock.try_lock(), Err(Error::WouldBlock)));
sleep(Duration::from_millis(200));
}
2 => {
let lock =
NamedLock::create(&uuid).expect("failed to create lock");

assert_matches!(lock.try_lock(), Err(Error::WouldBlock));
assert!(matches!(lock.try_lock(), Err(Error::WouldBlock)));
let _guard = lock.lock().expect("failed to lock");
sleep(Duration::from_millis(300));
}
Expand All @@ -243,20 +242,20 @@ mod tests {

#[test]
fn edge_cases() -> Result<()> {
let uuid = Uuid::new_v4().to_hyphenated().to_string();
let uuid = Uuid::new_v4().as_hyphenated().to_string();
let lock1 = NamedLock::create(&uuid)?;
let lock2 = NamedLock::create(&uuid)?;

{
let _guard1 = lock1.try_lock()?;
assert_matches!(lock1.try_lock(), Err(Error::WouldBlock));
assert_matches!(lock2.try_lock(), Err(Error::WouldBlock));
assert!(matches!(lock1.try_lock(), Err(Error::WouldBlock)));
assert!(matches!(lock2.try_lock(), Err(Error::WouldBlock)));
}

{
let _guard2 = lock2.try_lock()?;
assert_matches!(lock1.try_lock(), Err(Error::WouldBlock));
assert_matches!(lock2.try_lock(), Err(Error::WouldBlock));
assert!(matches!(lock1.try_lock(), Err(Error::WouldBlock)));
assert!(matches!(lock2.try_lock(), Err(Error::WouldBlock)));
}

Ok(())
Expand Down

0 comments on commit 04004ee

Please sign in to comment.