forked from mtusi2026/mtusi2026lab7
28 lines
897 B
Python
28 lines
897 B
Python
from concurrent.futures import ThreadPoolExecutor
|
|
from threading import Event
|
|
|
|
from scripts.bootstrap_security import write_private
|
|
|
|
|
|
def test_parallel_private_writes_are_complete_and_keep_permissions(tmp_path):
|
|
target = tmp_path / "snapshot.json"
|
|
payloads = [bytes([index]) * 32768 for index in range(16)]
|
|
write_private(target, payloads[0])
|
|
done = Event()
|
|
|
|
def read_during_writes():
|
|
while not done.is_set():
|
|
assert target.read_bytes() in payloads
|
|
|
|
with ThreadPoolExecutor(max_workers=9) as pool:
|
|
reader = pool.submit(read_during_writes)
|
|
try:
|
|
list(pool.map(lambda data: write_private(target, data), payloads))
|
|
finally:
|
|
done.set()
|
|
reader.result(timeout=5)
|
|
|
|
assert target.read_bytes() in payloads
|
|
assert target.stat().st_mode & 0o777 == 0o600
|
|
assert not list(tmp_path.glob("*.new"))
|