Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6359f3d

Browse files
committed
check that stopped callback is called
1 parent 19c07f1 commit 6359f3d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎scheduler/tests/test_worker/test_worker_commands.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import json
22
from threading import Thread
33
from time import sleep
4+
from unittest import mock
45

56
from scheduler.helpers.queues import get_queue
67
from scheduler.tests.jobs import test_job, two_seconds_job
78
from ..test_views.base import BaseTestCase
9+
from ...helpers.callback import Callback
810
from ...redis_models import JobModel, JobStatus, WorkerModel
911
from ...worker import create_worker
1012
from ...worker.commands import send_command, StopJobCommand
1113
from ...worker.commands.suspend_worker import SuspendWorkCommand
1214

1315

16+
def _callback_func():
17+
pass
18+
19+
20+
def callback_func():
21+
pass
22+
23+
1424
class WorkerCommandsTest(BaseTestCase):
1525
def test_stop_worker_command__green(self):
1626
# Arrange
@@ -45,11 +55,12 @@ def test_stop_worker_command__bad_worker_name(self):
4555
job = JobModel.get(job.name, connection=queue.connection)
4656
self.assertFalse(job.is_queued)
4757

48-
def test_stop_job_command__success(self):
58+
@mock.patch("scheduler.redis_models.job.JobModel.call_stopped_callback")
59+
def test_stop_job_command__success(self, mock_stopped_callback):
4960
# Arrange
5061
worker_name = "test"
5162
queue = get_queue("default")
52-
job = queue.create_and_enqueue_job(two_seconds_job)
63+
job = queue.create_and_enqueue_job(two_seconds_job, on_stopped=Callback(callback_func))
5364
self.assertTrue(job.is_queued)
5465
worker = create_worker("default", name=worker_name, burst=True, with_scheduler=False)
5566
worker.bootstrap()
@@ -70,3 +81,4 @@ def test_stop_job_command__success(self):
7081
self.assertIsNone(worker.current_job_name)
7182
self.assertEqual(job.status, JobStatus.STOPPED)
7283
t.join()
84+
mock_stopped_callback.assert_called()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /