Skip to content

Commit

Permalink
tests: fix the rest of Worker.update_worker related tests
Browse files Browse the repository at this point in the history
Related: #68
  • Loading branch information
lzaoral committed Aug 23, 2023
1 parent d83474b commit b7bc9d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
25 changes: 23 additions & 2 deletions tests/test_taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,39 @@ def setUp(self):
self._user = user
self._worker = RpcServiceMock(w)

@pytest.mark.xfail(reason='Check issue #68 for more info (https://git.io/fxSZ2).')
@patch('kobo.worker.taskmanager.HubProxy', HubProxyMock)
def test_update_worker_info(self):
tm = TaskManager(conf={'worker': self._worker})
self.assertTrue(tm.worker_info['enabled'])
self.assertTrue(tm.worker_info['ready'])
self.assertEqual(tm.worker_info['task_count'], 0)

tm.worker_info['enabled'] = False
tm.worker_info['ready'] = False
tm.update_worker_info()
self.assertFalse(tm.worker_info['enabled'])

# no open tasks, info won't be updated
self.assertTrue(tm.worker_info['enabled'])
self.assertTrue(tm.worker_info['ready'])
self.assertEqual(tm.worker_info['task_count'], 0)

Task.objects.create(
worker=self._worker.worker,
arch=self._arch,
channel=self._channel,
owner=self._user,
method='DummyForkTask',
state=TASK_STATES['OPEN'],
)

tm.worker_info['enabled'] = False
tm.worker_info['ready'] = False
tm.update_worker_info()

# open task, info will be updated
self.assertTrue(tm.worker_info['enabled'])
self.assertFalse(tm.worker_info['ready'])
self.assertEqual(tm.worker_info['task_count'], 1)

@patch('kobo.worker.taskmanager.HubProxy', HubProxyMock)
def test_update_worker_info_catch_protocol_error(self):
Expand Down
21 changes: 18 additions & 3 deletions tests/test_xmlrpc_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,32 @@ def test_set_task_weight_fails_if_another_worker_task(self):
t = Task.objects.get(id=t.id)
self.assertEqual(t.weight, 1)

@pytest.mark.xfail(reason='Check issue #68 for more info (https://git.io/fxSZ2).')
def test_update_worker(self):
req = _make_request(self._worker)

self.assertTrue(self._worker.enabled)
self.assertTrue(self._worker.ready)
self.assertEqual(self._worker.task_count, 0)

wi = worker.update_worker(req, False, False, 1)
# no open tasks, info won't be updated
wi = worker.update_worker(req, True, False, 1)

self.assertFalse(wi['enabled'])
self.assertTrue(wi['enabled'])
self.assertTrue(wi['ready'])
self.assertEqual(wi['task_count'], 0)

Task.objects.create(
worker=self._worker,
arch=self._arch,
channel=self._channel,
owner=self._user,
state=TASK_STATES['OPEN'],
)

wi = worker.update_worker(req, True, False, 1)

# open task, info will be updated
self.assertTrue(wi['enabled'])
self.assertFalse(wi['ready'])
self.assertEqual(wi['task_count'], 1)

Expand Down

0 comments on commit b7bc9d6

Please sign in to comment.