清單 1. queuemgr.xml 中的 check-queue 函數
<function name="check-queue">
<sequence>
<block name="'Queue Manager'">
<sequence>
<stafcmd name="'Check Queue'">
<location>'local'</location>
<service>'FS'</service>
<request>'LIST DIRECTORY %s TYPE F SORTBYNAME' % queueDir</request>
</stafcmd>
<script>dirList = STAFResult</script>
<script>taskCount = len(dirList)</script>
<script>
if (taskCount != 0): # skip an empty list
taskParam = dirList[0] # get first entry
else:
taskParam = "empty"
</script>
<if expr=" taskParam != 'empty'">
<if expr=" lastTaskParam != taskParam">
<sequence>
<if expr="TestRunInProgress[0] == 0">
<script>
TestRunInProgress[0] = 1
TestRunStartTime[0] = now()
</script>
</if>
<script>TestRunCtr[0] = TestRunCtr[0] + 1</script>
<script> lastTaskParam = taskParam </script>
<script> lastTaskParamJobID = taskParamJobID </script>
<log>'QueueMgr: Executing taskParam %s' %(taskParam)</log>
<stafcmd name="'Executing Task: %s' % taskParam">
<location>'local'</location>
<service>'STAX'</service>
<request>'EXECUTE FILE %s CLEARLOGS JOBNAME %s SCRIPT " taskParam='%s'" WAIT
%s' %(TestExecuteFile, taskParam, taskParam,gblTestExecutionTimeoutMS)</request>
</stafcmd>
<script> taskParamJobID = STAFResult</script>
<log>'QueueMgr: taskParam %s JobID = %s' %( taskParam, taskParamJobID)</log>
<if expr="RC != STAFRC.Ok">
<sequence>
<log>'QueueMgr: Execute Test with Param File %s failed - RC: %s STAFResult: %s'
%( taskParam,RC,STAFResult)</log>
<terminate block="'main'"/>
</sequence>
</if>
</sequence>
<else>
<sequence>
<log>'QueueMgr: *** TERMINATING Queue Manager *** Task File %s is the same as the
last one' %( taskParam)</log>
<log>'QueueMgr: Please check the completion status of Test Record %s Job ID %s
and Re-Start the Queue Manager' %( lastTaskParam, lastTaskParamJobID)</log>
<terminate block="'main'"/>
</sequence>
</else>
</if>
<else>
<sequence>
<if expr="TestRunInProgress[0] == 1">
<sequence>
<script>
TestRunInProgress[0] = 0
TestRunStopTime[0] = now()
testTime = (TestRunStopTime[0] - TestRunStartTime[0])
testHrs = int((testTime) / 3600)
testMin = int((testTime - (testHrs * 3600)) / 60)
testSec = int((testTime - (testHrs * 3600)) - (testMin * 60))
TestRunCompletionDateTime = strftime('%a %b %d %Y %H:%M:%S', localtime())
</script>
<log>'All tests have been run; the testqueue is empty'</log>
<log>'Test Run Completed: %s' % TestRunCompletionDateTime</log>
<log>'%d Test Tasks Were Completed In %d Hrs %d Min %d Sec'
% (TestRunCtr[0],testHrs,testMin,testSec)</log>
<script>TestRunCtr[0] = 0</script>
<terminate block="'main'"/>
</sequence>
</if>
<block name="'Queue Check Delay'">
<stafcmd name="'Checking TestQueue Every 5000 Sec' % gblCheckQueueDelayTimeSec">
<location>'local'</location>
<service>'DELAY'</service>
<request>'DELAY 5000'</request>
</stafcmd>
</block>
</sequence>
</else>
</if>
<block name="'Queue Process Delay'">
<stafcmd name="'Checking TestQueue 5000 Sec After Last Task'">
<location>'local'</location>
<service>'DELAY'</service>
<request>'DELAY 5000'</request>
</stafcmd>
</block>
</sequence>
</block>
</sequence>
</function>
代碼中第一個延時等待是對空任務隊列的查看周期。測試執行人員根據個人習慣有時候希望先啟動任務隊列執行任務,再生成測試任務參數文件。這時查看隊列的循環不能在第一次遇到隊列為空時就退出,而是要不斷反復查看任務隊列。如果在循環之間不加延時,會造成進程對 CPU 開銷過大,影響其他進程。第二個延時是前后兩個測試任務執行之間的延時。這是為了讓剛結束的測試進程有足夠時間釋放各種資源和執行多個文件操作,如日志文件和測試參數文件的轉移。
每次循環中獲得測試任務文件列表時要判斷第一個任務參數文件是否在上次循環中已經嘗試執行過。若是,則上次任務肯定沒有正常結束,否則應該將該任務文件轉移到任務結果文件夾中。這時應該中止任務隊列處理進程,提示測試執行人員查看 STAX 日志排除錯誤。
生成任務參數文件并啟動任務隊列執行的 PHP 代碼如下。該部分代碼在測試者提交了圖 3 所示的測試任務配置表單后執行。
文章來源于領測軟件測試網 http://www.kjueaiud.com/