Fix worker db
This commit is contained in:
@@ -406,6 +406,63 @@ def test_locked_database_surfaces_and_does_not_kill_worker_thread(tmp_path, monk
|
||||
blocker.execute("ROLLBACK")
|
||||
|
||||
|
||||
def test_worker_store_serializes_write_transactions(tmp_path, monkeypatch):
|
||||
import sqlite3
|
||||
|
||||
store = Store(settings_for(tmp_path).db_path)
|
||||
monkeypatch.setattr(store, "connect", lambda: sqlite3.connect(store.path, timeout=0.05,
|
||||
isolation_level=None))
|
||||
first_entered = Event()
|
||||
release_first = Event()
|
||||
second_started = Event()
|
||||
second_done = Event()
|
||||
errors = []
|
||||
|
||||
def first_writer():
|
||||
try:
|
||||
with store.tx():
|
||||
first_entered.set()
|
||||
release_first.wait(2)
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
|
||||
def second_writer():
|
||||
second_started.set()
|
||||
try:
|
||||
store.claim_page(1800, 2)
|
||||
except Exception as exc:
|
||||
errors.append(exc)
|
||||
finally:
|
||||
second_done.set()
|
||||
|
||||
first = Thread(target=first_writer)
|
||||
second = Thread(target=second_writer)
|
||||
first.start()
|
||||
try:
|
||||
assert first_entered.wait(2)
|
||||
second.start()
|
||||
assert second_started.wait(2)
|
||||
assert not second_done.wait(0.1)
|
||||
finally:
|
||||
release_first.set()
|
||||
first.join(2)
|
||||
if second.ident is not None:
|
||||
second.join(2)
|
||||
assert second_done.is_set()
|
||||
assert not errors
|
||||
|
||||
|
||||
def test_worker_main_loop_exits_when_processing_thread_stops(tmp_path):
|
||||
worker = Worker(settings_for(tmp_path))
|
||||
dead_thread = Thread(name="dead-ocr")
|
||||
try:
|
||||
worker.loop(lambda: False, [dead_thread])
|
||||
except RuntimeError as exc:
|
||||
assert "dead-ocr" in str(exc)
|
||||
else:
|
||||
raise AssertionError("Worker must exit so Docker can restart it")
|
||||
|
||||
|
||||
def test_real_http_ocr_and_callback(tmp_path):
|
||||
callbacks = []
|
||||
auth_headers = []
|
||||
@@ -593,4 +650,3 @@ def test_voffice_decryption_rejects_wrong_key(tmp_path):
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("Invalid encrypted document was accepted")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user