@@ -364,6 +364,19 @@ def setUp(self):
364364 db_name = "some_db" ,
365365 syntax_type = 1 ,
366366 )
367+ self .wf_executing = SqlWorkflow .objects .create (
368+ workflow_name = "some_name" ,
369+ group_id = 1 ,
370+ group_name = "g1" ,
371+ engineer_display = "" ,
372+ audit_auth_groups = "some_group" ,
373+ create_time = datetime .datetime .now (),
374+ status = "workflow_executing" ,
375+ is_backup = True ,
376+ instance = self .ins ,
377+ db_name = "some_db" ,
378+ syntax_type = 1 ,
379+ )
367380 SqlWorkflowContent .objects .create (
368381 workflow = self .wf ,
369382 sql_content = "some_sql" ,
@@ -409,6 +422,24 @@ def test_execute(self, _get_engine, _execute_workflow, _audit):
409422 operator_display = "系统" ,
410423 )
411424
425+ @patch ("sql.utils.execute_sql.Audit" )
426+ @patch ("sql.engines.mysql.MysqlEngine.execute_workflow" )
427+ @patch ("sql.engines.get_engine" )
428+ def test_execute_in_executing (self , _get_engine , _execute_workflow , _audit ):
429+ _audit .detail_by_workflow_id .return_value .audit_id = 1
430+ result = execute (self .wf_executing .id )
431+ _audit .add_log .assert_called_with (
432+ audit_id = 1 ,
433+ operation_type = 5 ,
434+ operation_type_desc = "执行工单发生异常" ,
435+ operation_info = "请检查工单执行情况" ,
436+ operator = "" ,
437+ operator_display = "系统" ,
438+ )
439+ assert result .error == (
440+ f"任务[{ self .wf_executing .id } ]被重试。可能是执行时发生超时,请检查数据库会话及执行状态,或联系管理员" ,
441+ )
442+
412443 @patch ("sql.utils.execute_sql.notify_for_execute" )
413444 @patch ("sql.utils.execute_sql.Audit" )
414445 def test_execute_callback_success (self , _audit , _notify ):
0 commit comments