aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/tests/test_lock.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_lock.py')
-rw-r--r--tests/test_lock.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/test_lock.py b/tests/test_lock.py
new file mode 100644
index 0000000..15d5e88
--- /dev/null
+++ b/tests/test_lock.py
@@ -0,0 +1,30 @@
+import fcntl
+import subprocess
+import sys
+import time
+import unittest
+
+from test_cli import Cli, WF
+
+
+class LockTest(Cli):
+ def test_write_waits_for_lock(self):
+ lock_path = self.root / ".wf" / "lock"
+ lock_path.parent.mkdir(exist_ok=True)
+ with open(lock_path, "w") as held:
+ fcntl.flock(held, fcntl.LOCK_EX)
+ p = subprocess.Popen([sys.executable, str(WF), "--project", str(self.root), "note", "t-three", "first"],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+ time.sleep(0.5)
+ self.assertIsNone(p.poll(), "write ran while the lock was held")
+ self.ok("show", "t-three") # read commands never wait
+ out, err = p.communicate(timeout=10)
+ self.assertEqual((p.returncode, err), (0, ""))
+ self.ok("note", "t-three", "second")
+ body = self.item("t-three")
+ self.assertIn("first", body)
+ self.assertIn("second", body)
+
+ def test_lock_file_is_git_ignored_folder(self):
+ self.ok("note", "t-three", "x")
+ self.assertEqual((self.root / ".wf" / ".gitignore").read_text(), "*\n")