mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-20 07:36:29 +00:00
Makes test_execution_limit_group_throttle_wait pass
Makes test_jobs_decorator.py::test_execution_limit_group_throttle_wait pass even when using group locks.
This commit is contained in:
parent
351de4d9a3
commit
c71daefd7f
@ -111,7 +111,7 @@ class Job(CoreSysAttributes):
|
|||||||
JobExecutionLimit.GROUP_WAIT: (JobConcurrency.GROUP_QUEUE, None),
|
JobExecutionLimit.GROUP_WAIT: (JobConcurrency.GROUP_QUEUE, None),
|
||||||
JobExecutionLimit.GROUP_THROTTLE: (None, JobThrottle.GROUP_THROTTLE),
|
JobExecutionLimit.GROUP_THROTTLE: (None, JobThrottle.GROUP_THROTTLE),
|
||||||
JobExecutionLimit.GROUP_THROTTLE_WAIT: (
|
JobExecutionLimit.GROUP_THROTTLE_WAIT: (
|
||||||
JobConcurrency.QUEUE, # Seems a bit counter intuitive, but GROUP_QUEUE deadlocks tests/jobs/test_job_decorator.py::test_execution_limit_group_throttle_wait
|
JobConcurrency.GROUP_QUEUE,
|
||||||
JobThrottle.GROUP_THROTTLE,
|
JobThrottle.GROUP_THROTTLE,
|
||||||
),
|
),
|
||||||
JobExecutionLimit.GROUP_THROTTLE_RATE_LIMIT: (
|
JobExecutionLimit.GROUP_THROTTLE_RATE_LIMIT: (
|
||||||
@ -148,19 +148,6 @@ class Job(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
self._rate_limited_calls = {}
|
self._rate_limited_calls = {}
|
||||||
|
|
||||||
if self.throttle in (
|
|
||||||
JobThrottle.GROUP_THROTTLE,
|
|
||||||
JobThrottle.GROUP_RATE_LIMIT,
|
|
||||||
) and self.concurrency in (
|
|
||||||
JobConcurrency.GROUP_REJECT,
|
|
||||||
JobConcurrency.GROUP_QUEUE,
|
|
||||||
):
|
|
||||||
# We cannot release group locks when Job is not running (e.g. throttled)
|
|
||||||
# which makes these combinations impossible to use currently.
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Job {self.name} is using group throttling ({self.throttle}) with group concurrency ({self.concurrency}), which is not allowed!"
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def throttle_max_calls(self) -> int:
|
def throttle_max_calls(self) -> int:
|
||||||
"""Return max calls for throttle."""
|
"""Return max calls for throttle."""
|
||||||
@ -505,7 +492,7 @@ class Job(CoreSysAttributes):
|
|||||||
JobConcurrency.GROUP_REJECT,
|
JobConcurrency.GROUP_REJECT,
|
||||||
JobConcurrency.GROUP_QUEUE,
|
JobConcurrency.GROUP_QUEUE,
|
||||||
):
|
):
|
||||||
if job_group and job_group.has_lock:
|
if job_group:
|
||||||
job_group.release()
|
job_group.release()
|
||||||
|
|
||||||
async def _handle_concurrency_control(
|
async def _handle_concurrency_control(
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from asyncio import Lock
|
from asyncio import Lock
|
||||||
|
|
||||||
from ..coresys import CoreSys, CoreSysAttributes
|
from ..coresys import CoreSys, CoreSysAttributes
|
||||||
from ..exceptions import JobException, JobGroupExecutionLimitExceeded
|
from ..exceptions import JobGroupExecutionLimitExceeded
|
||||||
from . import SupervisorJob
|
from . import SupervisorJob
|
||||||
|
|
||||||
|
|
||||||
@ -70,10 +70,11 @@ class JobGroup(CoreSysAttributes):
|
|||||||
self._active_job = job
|
self._active_job = job
|
||||||
|
|
||||||
def release(self) -> None:
|
def release(self) -> None:
|
||||||
"""Release the lock for the group or return it to parent."""
|
"""Release the lock for the group or return it to parent.
|
||||||
if not self.has_lock:
|
|
||||||
raise JobException("Cannot release as caller does not own lock")
|
|
||||||
|
|
||||||
|
It is the callers responsibility to ensure that the lock is only released
|
||||||
|
when the lock is actually being held.
|
||||||
|
"""
|
||||||
if self._parent_jobs:
|
if self._parent_jobs:
|
||||||
self._active_job = self._parent_jobs.pop()
|
self._active_job = self._parent_jobs.pop()
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user