Ejemplo n.º 1
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];
            for (int i = 0; i < taskList.Length; i++)
            {
                var session = sessionList[i];
                var caseStep = CaseStep.Create(setting.CaseStepTypeFormat, stepName);
                if (caseStep != null)
                {
                    caseStep.Runtimes = runtimes;
                    caseStep.Init(session);
                    caseList[i] = caseStep;
                    taskList[i] = Task.Factory.StartNew(caseStep.StartRun);
                }
            }
            if (setting.WaitTimeout == TimeSpan.Zero)
            {
                Task.WaitAll(taskList);
            }
            else
            {
                Task.WaitAll(taskList, setting.WaitTimeout);
            }

            int errorCount = caseList.Sum(t => t.Timer.FailNum);
            DoStepResult(stepBuilder, stepName, caseList);
            return errorCount;
        }
Ejemplo n.º 2
0
        internal protected virtual void Init(ThreadSession session, TaskSetting setting, Dictionary <string, string> parentData = null)
        {
            _session = session;
            _setting = setting;
            int msgId = _stepTimer.Runtimes + 1;

            SetRequestParam("MsgId", msgId);
            SetRequestParam("Sid", _session.Context.SessionId);
            SetRequestParam("Uid", _session.Context.UserId);
            SetRequestParam("ActionId", Action);
            foreach (var v in setting.childStepDic)
            {
                childDic.Add(v.Key, v.Value);
            }
            if (setting.StepParms.ContainsKey(Action))
            {
                foreach (var v in setting.StepParms[Action])
                {
                    SetRequestParam(v.Key, v.Value);
                }
            }
            if (parentData != null) // parent's data will override the config/init data.
            {
                foreach (var v in parentData)
                {
                    SetRequestParam(v.Key, v.Value);
                }
            }
        }
Ejemplo n.º 3
0
 private static void DoTotalResult(StringBuilder writer, TaskSetting setting, int errorCount)
 {
     writer.AppendLine("---------------------------------------------------");
     writer.AppendFormat("ThreadNum:\t{0}", setting.ThreadNum);
     writer.AppendLine();
     writer.AppendFormat("Runtimes:\t{0}", setting.Runtimes);
     writer.AppendLine();
     writer.AppendFormat("Run steps:\t{0}", string.Join(",", setting.CaseStepList));
     writer.AppendLine();
     writer.AppendFormat("Faild count:\t{0}", errorCount);
     writer.AppendLine();
 }
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();
        }
Ejemplo n.º 5
0
        protected void SetChildStep(string stepName, TaskSetting setting, Dictionary <string, string> parentData)
        {
            CaseStep caseStep = null;

            if (!string.IsNullOrEmpty(stepName))
            {
                caseStep = Create(_session.Setting.CaseStepTypeFormat, stepName, indentify);
                if (caseStep == null)
                {
                    throw new Exception(string.Format(_session.Setting.CaseStepTypeFormat, stepName) + " isn't found.");
                }
                caseStep.Runtimes = 1;
                caseStep.Init(_session, setting, parentData);
            }
            ChildStep = caseStep;
        }
Ejemplo n.º 6
0
        public static string RunTest(TaskSetting setting)
        {
            var sessionList = new List <ThreadSession>();

            for (int i = 0; i < setting.ThreadNum; i++)
            {
                sessionList.Add(new ThreadSession(i)
                {
                    Setting = setting
                });
            }

            StringBuilder mainBuilder = new StringBuilder();
            StringBuilder stepBuilder = new StringBuilder();
            int           errorCount  = 0;

            if (setting.CaseStepList.Count == 0)
            {
                mainBuilder.AppendFormat("CaseStep is not setting.");
                mainBuilder.AppendLine();
            }
            else
            {
                int index = 0;
                foreach (var step in setting.CaseStepList)
                {
                    var    arr      = step.Split('-');
                    string stepName = arr[0];

                    int runtimes = setting.Runtimes;
                    errorCount += RunStep(stepBuilder, sessionList, setting, stepName, runtimes);
                    if (arr.Length > 1)
                    {
                        //runtimes = arr[1].ToInt();
                        Thread.Sleep(arr[1].ToInt());
                    }
                }
            }

            DoTotalResult(mainBuilder, setting, errorCount);
            mainBuilder.Append(stepBuilder);
            mainBuilder.AppendLine("Finish testing.");
            return(mainBuilder.ToString());
        }
Ejemplo n.º 7
0
        public static string RunTest(TaskSetting setting)
        {
            var sessionList = new List<ThreadSession>();
            for (int i = 0; i < setting.ThreadNum; i++)
            {
                sessionList.Add(new ThreadSession(i) { Setting = setting });
            }

            StringBuilder mainBuilder = new StringBuilder();
            StringBuilder stepBuilder = new StringBuilder();
            int errorCount = 0;
            if (setting.CaseStepList.Count == 0)
            {
                mainBuilder.AppendFormat("CaseStep is not setting.");
                mainBuilder.AppendLine();
            }
            else
            {
                int index = 0;
                foreach (var step in setting.CaseStepList)
                {
                    var arr = step.Split('-');
                    string stepName = arr[0];

                    int runtimes = setting.Runtimes;
                    errorCount += RunStep(stepBuilder, sessionList, setting, stepName, runtimes);
                    if (arr.Length > 1)
                    {
                        //runtimes = arr[1].ToInt();
                        Thread.Sleep(arr[1].ToInt());
                    }
                }
            }

            DoTotalResult(mainBuilder, setting, errorCount);
            mainBuilder.Append(stepBuilder);
            mainBuilder.AppendLine("Finish testing.");
            return mainBuilder.ToString();
        }
Ejemplo n.º 8
0
 private static void DoTotalResult(StringBuilder writer, TaskSetting setting, int errorCount)
 {
     writer.AppendFormat("-------------------{0}-----------------------\n",DateTime.Now.ToString());
     writer.AppendFormat("ThreadNum:\t{0}", setting.ThreadNum);
     writer.AppendLine();
     writer.AppendFormat("Runtimes:\t{0}", setting.Runtimes);
     writer.AppendLine();
     writer.AppendFormat("Run steps:\t{0}", string.Join(",", setting.CaseStepList));
     writer.AppendLine();
     writer.AppendFormat("Faild count:\t{0}", errorCount);
     writer.AppendLine();
 }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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];
            for (int i = 0; i < taskList.Length; i++)
            {
                var session  = sessionList[i];
                var caseStep = CaseStep.Create(setting.CaseStepTypeFormat, stepName);
                if (caseStep != null)
                {
                    caseStep.Runtimes = runtimes;
                    caseStep.Init(session);
                    caseList[i] = caseStep;
                    taskList[i] = Task.Factory.StartNew(caseStep.StartRun);
                }
            }
            if (setting.WaitTimeout == TimeSpan.Zero)
            {
                Task.WaitAll(taskList);
            }
            else
            {
                Task.WaitAll(taskList, setting.WaitTimeout);
            }

            int errorCount = caseList.Sum(t => t.Timer.FailNum);

            DoStepResult(stepBuilder, stepName, caseList);
            return(errorCount);
        }
Ejemplo n.º 11
0
 protected void SetChildStep(string stepName , TaskSetting setting,Dictionary<string,string> parentData)
 {
     CaseStep caseStep = null;
     if (!string.IsNullOrEmpty(stepName))
     {
         caseStep = Create(_session.Setting.CaseStepTypeFormat, stepName,indentify);
         if (caseStep == null) throw new Exception(string.Format(_session.Setting.CaseStepTypeFormat, stepName) + " isn't found.");
         caseStep.Runtimes = 1;
         caseStep.Init(_session,setting,parentData);
     }
     ChildStep        = caseStep;
 }
Ejemplo n.º 12
0
 protected internal virtual void Init(ThreadSession session,TaskSetting setting,Dictionary<string,string> parentData=null)
 {
     _session = session;
     _setting = setting;
     int msgId = _stepTimer.Runtimes + 1;
     SetRequestParam("MsgId", msgId);
     SetRequestParam("Sid", _session.Context.SessionId);
     SetRequestParam("Uid", _session.Context.UserId);
     SetRequestParam("ActionId", Action);
     foreach(var v in setting.childStepDic)
     {
         childDic.Add(v.Key, v.Value);
     }
     if(setting.StepParms.ContainsKey(Action))
     {
         foreach(var v in setting.StepParms[Action])
         {
             SetRequestParam(v.Key, v.Value);
         }
     }
     if(parentData!=null) // parent's data will override the config/init data.
     {
         foreach(var v in parentData)
         {
             SetRequestParam(v.Key, v.Value);
         }
     }
 }
Ejemplo n.º 13
0
 public autoTaskData()
 {
     setting = new TaskSetting();
 }
Ejemplo n.º 14
0
 public autoTaskData()
 {
     setting = new TaskSetting();
 }