From 81d4e80fd5aabe4e80f58e960affa795cf7d34ec Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 07:27:17 +0200 Subject: workflow: initial public history --- tests/test_lock.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_lock.py (limited to 'tests/test_lock.py') 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") -- cgit