def test_failed_next_item(self, mocked_logger): self.reset() liveaction_db = self._create_liveaction_db() schedule_q_db = self.scheduler._create_execution_queue_item_db_from_liveaction( liveaction_db, ) schedule_q_db = ActionExecutionSchedulingQueue.add_or_update( schedule_q_db) with mock.patch( 'st2actions.scheduler.handler.ActionExecutionSchedulingQueue.add_or_update', side_effect=db_exc.StackStormDBObjectWriteConflictError( schedule_q_db)): schedule_q_db = self.scheduling_queue._get_next_execution() self.assertIsNone(schedule_q_db) mocked_logger.info.assert_called_once() call_args = mocked_logger.info.call_args_list[0][0] self.assertEqual( r'Execution queue item handled by another scheduler: %s', call_args[0]) schedule_q_db = self.scheduling_queue._get_next_execution() self.assertIsNotNone(schedule_q_db) ActionExecutionSchedulingQueue.delete(schedule_q_db)
def test_failed_next_item(self, mocked_logger): self.reset() liveaction_db = self._create_liveaction_db() schedule_q_db = self.scheduler._create_execution_queue_item_db_from_liveaction( liveaction_db, ) schedule_q_db = ActionExecutionSchedulingQueue.add_or_update( schedule_q_db) with mock.patch( "st2actions.scheduler.handler.ActionExecutionSchedulingQueue.add_or_update", side_effect=db_exc.StackStormDBObjectWriteConflictError( schedule_q_db), ): schedule_q_db = self.scheduling_queue._get_next_execution() self.assertIsNone(schedule_q_db) self.assertEqual(mocked_logger.info.call_count, 2) call_args = mocked_logger.info.call_args_list[1][0] self.assertEqual( r'[%s] Item "%s" is already handled by another scheduler.', call_args[0]) schedule_q_db = self.scheduling_queue._get_next_execution() self.assertIsNotNone(schedule_q_db) ActionExecutionSchedulingQueue.delete(schedule_q_db)
def save(self, instance, validate=True): if not hasattr(instance, 'id') or not instance.id: return self.insert(instance) else: try: save_condition = {'id': instance.id, 'rev': instance.rev} instance.rev = instance.rev + 1 instance.save(save_condition=save_condition, validate=validate) except mongoengine.SaveConditionError: raise db_exc.StackStormDBObjectWriteConflictError(instance) return self._undo_dict_field_escape(instance)
def mock_wf_db_update_conflict(wf_ex_db, publish=True, dispatch_trigger=True, **kwargs): seq_len = len(wf_ex_db.state['sequence']) if seq_len > 0: current_task_id = wf_ex_db.state['sequence'][seq_len - 1:][0]['id'] temp_file_path = TEMP_DIR_PATH + '/' + current_task_id if os.path.exists(temp_file_path): os.remove(temp_file_path) raise db_exc.StackStormDBObjectWriteConflictError(wf_ex_db) return wf_db_access.WorkflowExecution._get_impl().update(wf_ex_db, **kwargs)
def test_retry_on_transient_db_errors(self): instance = wf_db_models.WorkflowExecutionDB() exc = db_exc.StackStormDBObjectWriteConflictError(instance) self.assertTrue(wf_exc.retry_on_transient_db_errors(exc))