Ver código fonte

1、修复BUG:当脚本初始化失败时,只标记了脚本结果为FAIL,却未标记脚本为已执行。导致该用例状态一起为未执行,使任务一直在该用例循环判断而不结束;
2、添加脚本初始化失败的日志输出,方便查找失败原因;

scbc.sat2 5 anos atrás
pai
commit
f096090ff0

+ 3 - 3
SATService/SATService/PythonExecutor.cpp

@@ -536,7 +536,7 @@ bool CPythonExecutor::InitScript(std::string strScript, std::string strLogPath,
 {
 	// 判断脚本是否存在;
 	if (!PathFileExists(strScript.c_str())) {
-		printf("Error:脚本文件不存在\n");
+		GLOBAL::WriteTextLog("【Error】脚本文件不存在:%s\n", strScript.c_str());
 		return false;
 	}
 
@@ -544,14 +544,14 @@ bool CPythonExecutor::InitScript(std::string strScript, std::string strLogPath,
 	if (!PathFileExists(strLogPath.c_str())) {
 		// 创建路径;
 		if (!GLOBAL::MKDIR(strLogPath.c_str())) {
-			printf("Error:创建目录失败\n");
+			GLOBAL::WriteTextLog("【Error】创建目录失败:%s\n", strLogPath.c_str());
 			return false;
 		}
 
 		// 创建文件;
 		std::ofstream flog(strLogPath.c_str());
 		if ( flog.bad() ) {
-			printf("Error:创建文件失败\n");
+			GLOBAL::WriteTextLog("【Error】创建文件失败:%ld,%s\n", GetLastError(), strLogPath.c_str());
 			return false;
 		}
 		flog.close();

+ 14 - 6
SATService/SATService/SATExecutor.cpp

@@ -119,13 +119,10 @@ SATHTTP::STCase* CSATExecutor::ExecuteFreeCaseScript(SATHTTP::STTask* pTask)
 					// 设置用例对象;
 					pExcutor->SetCaseObje(pCase);
 					pExcutor->StartScript();
-					// 标记用例执行中;
-					pCase->_nExecutionState = SATHTTP::INEXECUTED;
-				}
-				else { // 标记脚本失败;
-					pCase->_nExecutionResult = SATHTTP::FAIL;
 				}
 
+				// 标记用例执行中;
+				pCase->_nExecutionState = SATHTTP::INEXECUTED;
 				// 标记任务为执行中;
 				pTask->_nExecutionState = SATHTTP::INEXECUTED;
 				// 记录开始时间;
@@ -134,7 +131,18 @@ SATHTTP::STCase* CSATExecutor::ExecuteFreeCaseScript(SATHTTP::STTask* pTask)
 			}	
 		}
 		else {
-			//CScriptExecutor *pExcutor = (CScriptExecutor *)pCase->_pExcutor;
+			// 重新初始化脚本;
+			CPythonExecutor *pExcutor = (CPythonExecutor *)pCase->_pExcutor;
+			if ( pExcutor->InitScript(pCase->_strScriptPath, pCase->_strCaseLog, "") ) {
+				// 设置用例对象;
+				pExcutor->SetCaseObje(pCase);
+				pExcutor->StartScript();
+				// 标记用例执行中;
+				pCase->_nExecutionState = SATHTTP::INEXECUTED;
+			}
+			else { // 如果再次初始化失败,标记脚本失败;
+				pCase->_nExecutionResult = SATHTTP::FAIL;
+			}
 		}
 	}