mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(conftest): use synchronization locks for setup_database
We were running into data race issues where the `fn.is_file()` check would occur twice before writing the file in the `else` clause. For this reason, a new aurweb.lock.Lock class has been added which doubles as a thread and process lock. We can use this elsewhere in the future, but we are also able to use it to solve this kind of data race issue. That being said, we still need the lock file state to tell us when the first caller acquired the lock. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
155aa47a1a
commit
4b0cb0721d
3 changed files with 95 additions and 24 deletions
26
test/test_filelock.py
Normal file
26
test/test_filelock.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import py
|
||||
|
||||
from _pytest.logging import LogCaptureFixture
|
||||
|
||||
from aurweb.testing.filelock import FileLock
|
||||
|
||||
|
||||
def test_filelock(tmpdir: py.path.local):
|
||||
cb_path = None
|
||||
|
||||
def setup(path: str):
|
||||
nonlocal cb_path
|
||||
cb_path = str(path)
|
||||
|
||||
flock = FileLock(tmpdir, "test")
|
||||
assert not flock.lock(on_create=setup)
|
||||
assert cb_path == str(tmpdir / "test")
|
||||
assert flock.lock()
|
||||
|
||||
|
||||
def test_filelock_default(caplog: LogCaptureFixture, tmpdir: py.path.local):
|
||||
# Test default_on_create here.
|
||||
flock = FileLock(tmpdir, "test")
|
||||
assert not flock.lock()
|
||||
assert caplog.messages[0] == f"Filelock at {flock.path} acquired."
|
||||
assert flock.lock()
|
Loading…
Add table
Add a link
Reference in a new issue