Protection multi-instance GUI V6 : mutex kernel nommé sur Windows (partagé avec l'installeur Inno via AppMutex), fcntl exclusif sur POSIX (dev/test). 3 tests unitaires, self-test OK, 0 régression gui_v6 (145 passed). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
838 B
Python
34 lines
838 B
Python
import pytest
|
|
|
|
from gui_v6.single_instance import (
|
|
APP_MUTEX_NAME,
|
|
AlreadyRunningError,
|
|
SingleInstance,
|
|
)
|
|
|
|
|
|
def test_mutex_name_is_stable():
|
|
# Nom partagé avec l'installeur (Inno AppMutex). Ne pas changer sans MAJ .iss.
|
|
assert APP_MUTEX_NAME == "AivanonymAnonymisationV6"
|
|
|
|
|
|
def test_second_instance_is_rejected(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
|
|
first = SingleInstance()
|
|
first.acquire()
|
|
try:
|
|
with pytest.raises(AlreadyRunningError):
|
|
SingleInstance().acquire()
|
|
finally:
|
|
first.release()
|
|
|
|
|
|
def test_release_allows_reacquire(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
|
|
a = SingleInstance()
|
|
a.acquire()
|
|
a.release()
|
|
b = SingleInstance()
|
|
b.acquire() # ne lève pas
|
|
b.release()
|