diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:39 +0000 |
commit | 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch) | |
tree | 3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/fd-lock/tests | |
parent | Releasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/fd-lock/tests')
-rw-r--r-- | vendor/fd-lock/tests/test.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/fd-lock/tests/test.rs b/vendor/fd-lock/tests/test.rs index 35fd5b33b..dc43ae073 100644 --- a/vendor/fd-lock/tests/test.rs +++ b/vendor/fd-lock/tests/test.rs @@ -31,3 +31,64 @@ fn double_write_lock() { drop(g0); } + +#[test] +fn read_and_write_lock() { + let dir = tempdir().unwrap(); + let path = dir.path().join("lockfile"); + + let l0 = RwLock::new(File::create(&path).unwrap()); + let mut l1 = RwLock::new(File::open(path).unwrap()); + + let g0 = l0.try_read().unwrap(); + + let err = l1.try_write().unwrap_err(); + assert!(matches!(err.kind(), ErrorKind::WouldBlock)); + + drop(g0); +} + +#[test] +fn write_and_read_lock() { + let dir = tempdir().unwrap(); + let path = dir.path().join("lockfile"); + + let mut l0 = RwLock::new(File::create(&path).unwrap()); + let l1 = RwLock::new(File::open(path).unwrap()); + + let g0 = l0.try_write().unwrap(); + + let err = l1.try_read().unwrap_err(); + assert!(matches!(err.kind(), ErrorKind::WouldBlock)); + + drop(g0); +} + +#[cfg(windows)] +mod windows { + use super::*; + use std::os::windows::fs::OpenOptionsExt; + + #[test] + fn try_lock_error() { + let dir = tempdir().unwrap(); + let path = dir.path().join("lockfile"); + + // On Windows, opening with an access_mode as 0 will prevent all locking operations from succeeding, simulating an I/O error. + let mut l0 = RwLock::new( + File::options() + .create(true) + .read(true) + .write(true) + .access_mode(0) + .open(path) + .unwrap(), + ); + + let err1 = l0.try_read().unwrap_err(); + assert!(matches!(err1.kind(), ErrorKind::PermissionDenied)); + + let err2 = l0.try_write().unwrap_err(); + assert!(matches!(err2.kind(), ErrorKind::PermissionDenied)); + } +} |