def test_without_session(self, get_session, debug): """Test the function without handing it a Koji session.""" tasks = [1, 2, 3] get_session.return_value.taskFinished.side_effect = [True, True, True] get_session.return_value.getTaskInfo.side_effect = [{ 'state': koji.TASK_STATES['CLOSED'] }, { 'state': koji.TASK_STATES['CLOSED'] }, { 'state': koji.TASK_STATES['CLOSED'] }] ret = buildsys.wait_for_tasks(tasks, sleep=0.01) self.assertEqual(ret, []) self.assertEqual(debug.mock_calls, [ mock.call('Waiting for 3 tasks to complete: [1, 2, 3]'), mock.call('3 tasks completed successfully, 0 tasks failed.') ]) get_session.assert_called_once_with() self.assertEqual( get_session.return_value.taskFinished.mock_calls, [mock.call(1), mock.call(2), mock.call(3)]) self.assertEqual( get_session.return_value.getTaskInfo.mock_calls, [mock.call(1), mock.call(2), mock.call(3)])
def test_with_successful_tasks(self, debug): """A list of successful tasks should return [].""" tasks = [1, 2, 3] session = mock.MagicMock() session.taskFinished.side_effect = [True, True, True] session.getTaskInfo.side_effect = [{ 'state': koji.TASK_STATES['CLOSED'] }, { 'state': koji.TASK_STATES['CLOSED'] }, { 'state': koji.TASK_STATES['CLOSED'] }] ret = buildsys.wait_for_tasks(tasks, session, sleep=0.01) self.assertEqual(ret, []) self.assertEqual(debug.mock_calls, [ mock.call('Waiting for 3 tasks to complete: [1, 2, 3]'), mock.call('3 tasks completed successfully, 0 tasks failed.') ]) self.assertEqual( session.taskFinished.mock_calls, [mock.call(1), mock.call(2), mock.call(3)]) self.assertEqual( session.getTaskInfo.mock_calls, [mock.call(1), mock.call(2), mock.call(3)])
def test_wait_on_unfinished_task(self, sleep, debug): """Assert that we wait on unfinished tasks for sleep seconds.""" tasks = [1, 2, 3] session = mock.MagicMock() session.taskFinished.side_effect = [True, False, False, True, True] session.getTaskInfo.return_value = { 'state': koji.TASK_STATES['CLOSED'] } ret = buildsys.wait_for_tasks(tasks, session, sleep=0.01) self.assertEqual(ret, []) self.assertEqual(debug.mock_calls, [ mock.call('Waiting for 3 tasks to complete: [1, 2, 3]'), mock.call('3 tasks completed successfully, 0 tasks failed.') ]) self.assertEqual(session.taskFinished.mock_calls, [ mock.call(1), mock.call(2), mock.call(2), mock.call(2), mock.call(3) ]) self.assertEqual(sleep.mock_calls, [mock.call(0.01), mock.call(0.01)]) self.assertEqual( session.getTaskInfo.mock_calls, [mock.call(1), mock.call(2), mock.call(3)])
def test_with_failed_task(self, debug): """Assert that we return a list of failed_tasks.""" tasks = [1, 2, 3] session = mock.MagicMock() session.taskFinished.side_effect = [True, True, True] session.getTaskInfo.side_effect = [{ 'state': koji.TASK_STATES['CLOSED'] }, { 'state': koji.TASK_STATES['FAILED'] }, { 'state': koji.TASK_STATES['CLOSED'] }] ret = buildsys.wait_for_tasks(tasks, session, sleep=0.01) assert ret == [2] assert debug.mock_calls == ([ mock.call('Waiting for 3 tasks to complete: [1, 2, 3]'), mock.call('2 tasks completed successfully, 1 tasks failed.') ]) assert session.taskFinished.mock_calls == [ mock.call(1), mock.call(2), mock.call(3) ] assert session.getTaskInfo.mock_calls == [ mock.call(1), mock.call(2), mock.call(3) ]
def _perform_tag_actions(self): koji = buildsys.get_session() for i, batches in enumerate([(self.add_tags_sync, self.move_tags_sync), (self.add_tags_async, self.move_tags_async)]): add, move = batches if i == 0: koji.multicall = False else: koji.multicall = True for action in add: tag, build = action self.log.info("Adding tag %s to %s" % (tag, build)) koji.tagBuild(tag, build, force=True) for action in move: from_tag, to_tag, build = action self.log.info('Moving %s from %s to %s' % ( build, from_tag, to_tag)) koji.moveBuild(from_tag, to_tag, build, force=True) if i != 0: results = koji.multiCall() failed_tasks = buildsys.wait_for_tasks([task[0] for task in results], koji, sleep=15) if failed_tasks: raise Exception("Failed to move builds: %s" % failed_tasks)
def test_with_falsey_task(self, debug): """Assert that a Falsey entry in the list doesn't raise an Exception.""" tasks = [1, False, 3] session = mock.MagicMock() session.taskFinished.side_effect = [True, True] session.getTaskInfo.side_effect = [ {'state': koji.TASK_STATES['CLOSED']}, {'state': koji.TASK_STATES['CLOSED']}] ret = buildsys.wait_for_tasks(tasks, session, sleep=0.01) self.assertEqual(ret, []) self.assertEqual( debug.mock_calls, [mock.call('Waiting for 3 tasks to complete: [1, False, 3]'), mock.call('Skipping task: False'), mock.call('3 tasks completed successfully, 0 tasks failed.')]) self.assertEqual(session.taskFinished.mock_calls, [mock.call(1), mock.call(3)]) self.assertEqual(session.getTaskInfo.mock_calls, [mock.call(1), mock.call(3)])