Ejemplo n.º 1
0
 protected CaseStep()
 {
     _stepTimer = new StepTimer();
     Action = "";
     _params = new Dictionary<string, string>();
     Runtimes = 1;
 }
Ejemplo n.º 2
0
 protected CaseStep()
 {
     _stepTimer = new StepTimer();
     Action = "";
     _caseStepParms = new Dictionary<string, string>();
     Runtimes = 1;
     childDic = new Dictionary<int, int>();
 }
Ejemplo n.º 3
0
 internal static int RunStep(StringBuilder stepBuilder, List<ThreadSession> sessionList, TaskSetting setting, string stepName, int runtimes)
 {
     CaseStep[] caseList = new CaseStep[sessionList.Count];
     Task[] taskList = new Task[sessionList.Count];
     StepTimer st = new StepTimer();
     st.Reset();
     st.StartTime();
     for (int i = 0; i < taskList.Length; i++)
     {
         ++cnt;
         var session = sessionList[i];
         var caseStep = CaseStep.Create(setting.CaseStepTypeFormat, stepName,cnt);
         if (caseStep != null)
         {
             caseStep.Runtimes = runtimes;
             caseStep.Init(session,setting);
             caseList[i] = caseStep;
             //Console.WriteLine("Task.Factory.StartNew:" + cnt);
             taskList[i] = Task.Factory.StartNew(caseStep.StartRun);
         }
     }
     if (setting.WaitTimeout == TimeSpan.Zero)
     {
         Task.WaitAll(taskList);
     }
     else
     {
         Task.WaitAll(taskList, setting.WaitTimeout);
     }
     st.Completed();
     st.DoResult();
     int errorCount = caseList.Sum(t => t.Timer.FailNum);
     DoStepResult(setting,stepBuilder, stepName, caseList,0,st);
     return errorCount;
 }
Ejemplo n.º 4
0
        private static void DoStepResult(TaskSetting setting, StringBuilder writer, string stepName, ICollection<CaseStep> steps, int depth = 0,StepTimer st=null)
        {
            string preChar = "".PadLeft(depth * 4);
            double minTime = steps.Min(t => t.Timer.MinTime);
            double aveTime = steps.Average(t => t.Timer.AveTime);
            double maxTime = steps.Max(t => t.Timer.MaxTime);
            int successNum = steps.Sum(t => t.Timer.SuccessNum);
            int failNum = steps.Sum(t => t.Timer.FailNum);
            if (failNum > 0)
            {
                string error = string.Join("", steps.Select(t => t.Timer.Error).ToList());
                TraceLog.WriteError("{0}", error);
            }
            writer.AppendFormat("====={0}-{1}({2})", setting.TaskName, stepName, DateTime.Now.ToString());
            writer.AppendLine();
            writer.AppendFormat("====={0}", setting.TaskDes);
            writer.AppendLine();
            writer.AppendFormat("{0}>>Step {1}: success:{2}, fail:{3}", preChar, stepName, successNum, failNum);
            writer.AppendLine();
            writer.AppendFormat("{0}    AVE:\t{1}ms", preChar, aveTime.ToString("F6"));
            writer.AppendLine();
            writer.AppendFormat("{0}    Min:\t{1}ms", preChar, minTime.ToString("F6"));
            writer.AppendLine();
            writer.AppendFormat("{0}    Max:\t{1}ms", preChar, maxTime.ToString("F6"));
            writer.AppendLine();
            writer.AppendFormat("{0}    TotalTime:\t{1}ms",preChar,st!=null ? st.RunTotalTime.ToString("F6"):"");
            writer.AppendLine();
            string info = "";
            foreach(var v in steps)
            {
                if (v.DecodePacketInfo!="")
                    info += v.DecodePacketInfo + "\n";
            }
            if(info != "")
            {
                writer.AppendFormat("req/res:\n{0}",info);
                writer.AppendLine();
            }

            var childs = steps.Where(t => t.ChildStep != null).Select(t => t.ChildStep).ToArray();
            if (childs.Length > 0)
            {
                DoStepResult(setting,writer, childs[0].Action, childs, depth + 1);
            }
            writer.AppendFormat("====={0}-{1}:End", setting.TaskName,stepName);
            writer.AppendLine();
        }