test: Cancel pending jobs in RQ tests (#32970)
This casues flake sometimes when other tests don't cleanup long running pending jobs.
This commit is contained in:
parent
764410761f
commit
7e2b4955f8
2 changed files with 16 additions and 0 deletions
|
|
@ -112,6 +112,16 @@ class RQJob(Document):
|
|||
except InvalidJobOperation:
|
||||
frappe.msgprint(_("Job is not running."), title=_("Invalid Operation"))
|
||||
|
||||
@check_permissions
|
||||
def cancel(self):
|
||||
if self.status == "queued":
|
||||
self.job.cancel()
|
||||
else:
|
||||
frappe.msgprint(
|
||||
_("Job is in {0} state and can't be cancelled").format(self.status),
|
||||
title=_("Invalid Operation"),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_count(filters=None) -> int:
|
||||
return len(RQJob.get_matching_job_ids(filters))
|
||||
|
|
|
|||
|
|
@ -26,6 +26,12 @@ def wait_for_completion(job: Job):
|
|||
class TestRQJob(IntegrationTestCase):
|
||||
BG_JOB = "frappe.core.doctype.rq_job.test_rq_job.test_func"
|
||||
|
||||
def setUp(self) -> None:
|
||||
# Cleanup all pending jobs
|
||||
for job in frappe.get_all("RQ Job", {"status": "queued"}):
|
||||
frappe.get_doc("RQ Job", job.name).cancel()
|
||||
return super().setUp()
|
||||
|
||||
def check_status(self, job: Job, status, wait=True):
|
||||
if wait:
|
||||
wait_for_completion(job)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue