Skip to content

Commit

Permalink
Merge pull request #222 from lzaoral/fix-tests-part2
Browse files Browse the repository at this point in the history
tests: fix the rest of tests marked as `XFAIL`
  • Loading branch information
rohanpm authored Aug 24, 2023
2 parents ce4fcff + b7bc9d6 commit 70dd8a6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
5 changes: 3 additions & 2 deletions kobo/hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,9 @@ def cancel_subtasks(self):
result = True
for task in self.subtasks():
try:
result &= task.cancel_task()
except (MultipleObjectsReturned, ObjectDoesNotExist):
task.cancel_task()
except Exception as e:
logger.error('Cannot cancel subtask %d: %s', task.id, e)
result = False
return result

Expand Down
1 change: 0 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,6 @@ def test_fail_task_with_invalid_initial_state(self):
with self.assertRaises(Exception):
task.fail_task()

@pytest.mark.xfail(reason='Check issue #89 for more info (https://git.io/fp6gq).')
def test_cancel_subtasks(self):
parent = Task.objects.create(
worker=self._worker,
Expand Down
15 changes: 10 additions & 5 deletions tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,18 @@ def test_run(self):
# bashism - output redirection to subshells
run("echo foo | tee >(md5sum -b) >/dev/null", executable="/bin/bash")

@pytest.mark.xfail(sys.version_info < (3, 7), reason="python3.7 api changes")
def test_run_in_text_mode(self):
"""test run with kwargs 'text', 'encoding' or/and 'errors' set. These kwargs are
added to Popen from python3.6(encoding, errors) and python3.7(text). Running test
with python version older than 3.7 is expected to fail
"""test run with kwargs 'text', 'encoding', 'universal_newlines' or/and
'errors' set.
Python 3.7 added 'text' as an alias for 'universal_newlines'.
"""
ret, out = run("echo hello", text=True)
if sys.version_info >= (3, 7):
ret, out = run("echo hello", text=True)
self.assertEqual(ret, 0)
self.assertEqual(out, "hello\n")

ret, out = run("echo hello", universal_newlines=True)
self.assertEqual(ret, 0)
self.assertEqual(out, "hello\n")

Expand Down
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 70dd8a6

Please sign in to comment.