Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 3s
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
from threading import Event
|
|
|
|
from dx_productivity.trial_task_center.ui.queries import LatestQuery
|
|
from dx_productivity.trial_task_center.ui.resource_status import ResourceStatus
|
|
|
|
|
|
def test_active_workers_excludes_cancelled_old_selection_and_is_immutable(qtbot):
|
|
query = LatestQuery()
|
|
first_started, second_started, release = Event(), Event(), Event()
|
|
def read(started):
|
|
started.set()
|
|
assert release.wait(5)
|
|
return ()
|
|
try:
|
|
query.request(lambda: read(first_started), lambda _: None, lambda _: None)
|
|
qtbot.waitUntil(first_started.is_set)
|
|
first = query.active_workers
|
|
assert isinstance(first, tuple) and len(first) == 1
|
|
query.request(lambda: read(second_started), lambda _: None, lambda _: None)
|
|
qtbot.waitUntil(second_started.is_set)
|
|
current = query.active_workers
|
|
assert len(current) == 1 and current[0] is not first[0]
|
|
query.invalidate()
|
|
assert query.active_workers == () and len(first) == 1
|
|
finally:
|
|
release.set()
|
|
qtbot.waitUntil(lambda: not query.busy)
|
|
query.close()
|
|
|
|
|
|
def test_resource_failures_count_actual_callbacks_and_success_resets(qtbot):
|
|
state = {'fail': True, 'calls': 0}
|
|
def read():
|
|
state['calls'] += 1
|
|
if state['fail']:
|
|
raise OSError('temporary local file failure')
|
|
return ()
|
|
status = ResourceStatus(read)
|
|
try:
|
|
assert status.consecutive_failures == 0
|
|
status.refresh()
|
|
qtbot.waitUntil(lambda: not status.busy)
|
|
assert status.consecutive_failures == 1
|
|
status.changed.emit()
|
|
assert status.consecutive_failures == 1
|
|
status.refresh()
|
|
qtbot.waitUntil(lambda: not status.busy)
|
|
assert status.consecutive_failures == 2
|
|
state['fail'] = False
|
|
status.refresh()
|
|
qtbot.waitUntil(lambda: not status.busy)
|
|
assert status.consecutive_failures == 0 and state['calls'] == 3
|
|
finally:
|
|
status.close()
|