Files
cbb-refresh-verify-795/tests/test_global_stop_queue_semantics.py
T

33 lines
1.4 KiB
Python

from threading import Event,Thread
from cbb_refresh_verify.operation_queue import QueueCancelled
from test_issue15_ui_integration import window_for
def test_actual_global_stop_button_cancels_running_and_same_app_queued_jobs(qtbot,tmp_path,monkeypatch):
window=window_for(qtbot,tmp_path,monkeypatch)
first=window._new_job('verify',library=tmp_path/'lib.lmc')
second=window._new_job('native_session',library=tmp_path/'lib.lmc')
entered,release,waiting,done=Event(),Event(),Event(),Event();calls=[];errors=[]
def current():
calls.append('first');entered.set();release.wait(3)
def run_first():
try:window.native_queue.run(current,context=first.context,stop=first.context.stop)
except QueueCancelled:pass
def queued():
try:window.native_queue.run(lambda:calls.append('second'),context=second.context,
stop=second.context.stop,waiting=waiting.set)
except QueueCancelled as error:errors.append(error)
finally:done.set()
a=Thread(target=run_first);b=Thread(target=queued)
a.start();assert entered.wait(2);b.start()
try:
qtbot.waitUntil(waiting.is_set);window._update()
assert window.stop_button.isEnabled()
window.stop_button.click()
qtbot.waitUntil(done.is_set)
assert first.context.stop.is_set() and second.context.stop.is_set()
assert calls==['first'] and len(errors)==1
finally:
release.set();a.join(3);b.join(3)