Example #1
0
def test_rwlock_reentrant(tmp_path):
    path = fspath(tmp_path)
    foo = PathInfo("foo")

    with rwlock(path, "cmd1", [], [foo]):
        with rwlock(path, "cmd1", [], [foo]):
            pass
        with _edit_rwlock(path) as lock:
            assert lock == {
                "read": {},
                "write": {
                    "foo": {
                        "cmd": "cmd1",
                        "pid": os.getpid()
                    }
                },
            }

    with rwlock(path, "cmd", [foo], []):
        with rwlock(path, "cmd", [foo], []):
            pass
        with _edit_rwlock(path) as lock:
            assert lock == {
                "read": {
                    "foo": [{
                        "cmd": "cmd",
                        "pid": os.getpid()
                    }]
                },
                "write": {},
            }
Example #2
0
def test_broken_rwlock(tmp_path):
    dir_path = fspath(tmp_path)
    path = tmp_path / "rwlock"

    path.write_text('{"broken": "format"}', encoding="utf-8")
    with pytest.raises(RWLockFileFormatError):
        with _edit_rwlock(dir_path):
            pass

    path.write_text("{broken json", encoding="utf-8")
    with pytest.raises(RWLockFileCorruptedError):
        with _edit_rwlock(dir_path):
            pass