summaryrefslogtreecommitdiffstats
path: root/vendor/fd-lock/tests/test.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/fd-lock/tests/test.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/fd-lock/tests/test.rs')
-rw-r--r--vendor/fd-lock/tests/test.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/fd-lock/tests/test.rs b/vendor/fd-lock/tests/test.rs
new file mode 100644
index 000000000..35fd5b33b
--- /dev/null
+++ b/vendor/fd-lock/tests/test.rs
@@ -0,0 +1,33 @@
+use fd_lock::RwLock;
+use std::fs::File;
+use std::io::ErrorKind;
+
+use tempfile::tempdir;
+
+#[test]
+fn double_read_lock() {
+ let dir = tempdir().unwrap();
+ let path = dir.path().join("lockfile");
+
+ let l0 = RwLock::new(File::create(&path).unwrap());
+ let l1 = RwLock::new(File::open(path).unwrap());
+
+ let _g0 = l0.try_read().unwrap();
+ let _g1 = l1.try_read().unwrap();
+}
+
+#[test]
+fn double_write_lock() {
+ let dir = tempdir().unwrap();
+ let path = dir.path().join("lockfile");
+
+ let mut l0 = RwLock::new(File::create(&path).unwrap());
+ let mut l1 = RwLock::new(File::open(path).unwrap());
+
+ let g0 = l0.try_write().unwrap();
+
+ let err = l1.try_write().unwrap_err();
+ assert!(matches!(err.kind(), ErrorKind::WouldBlock));
+
+ drop(g0);
+}