public void JS_VerifyTimeTravelDebugging()

in AmbrosiaTest/AmbrosiaTest/JS_Utilities.cs [477:651]


        public void JS_VerifyTimeTravelDebugging(string testName, int numRounds, long totalBytes, long totalEchoBytes, int bytesPerRound, int maxMessageSize, int batchSizeCutoff, bool bidi, bool checkForDoneString = true, string specialVerifyString = "", string instanceRole = "", string serverInstanceName = "", int serverlognum = 1)
        {
            Utilities MyUtils = new Utilities();

            string currentDir = Directory.GetCurrentDirectory();
            string bytesReceivedString = "Bytes received: " + totalBytes.ToString();
            string successString = "SUCCESS: The expected number of bytes (" + totalBytes.ToString() + ") have been received";
            string successEchoString = "SUCCESS: The expected number of echoed bytes (" + totalBytes.ToString() + ") have been received";
            string allRoundsComplete = "All rounds complete";
            string argForTTD = "Args: DebugInstance instanceName=" + testName+instanceRole.ToLower();
            string startingCheckPoint = "checkpoint="; // append the number below after calculated
            string workingDir = MyUtils.baseAmbrosiaPath + ConfigurationManager.AppSettings["AmbrosiaJSPTIDirectory"] + JSPTI_AppPath;  // defaults to Combined (app)
            string logOutputFileName_TestApp = testName + "_" + instanceRole + "_VerifyTTD_"+ serverlognum.ToString() + ".log";
            string fileNameExe = "node.exe";
            string argString = "out\\main.js";
            string strLogFileInstanceRole = "";  // app instanceRole is blank

            // Make sure all node etc are stopped 
            MyUtils.StopAllAmbrosiaProcesses();

            // Instance Role defaults to Combined
            if (instanceRole == "")
            {
                argString = argString + " -ir=" + JSPTI_CombinedInstanceRole;
            }
            else
            {
                argString = argString + " -ir=" + instanceRole;
                strLogFileInstanceRole = instanceRole;  // used in the file name of the log
            }
            string ambrosiaBaseLogDir = MyUtils.baseAmbrosiaPath + ConfigurationManager.AppSettings["AmbrosiaLogDirectory"];  // don't put + "\\" on end as mess up location .. need append in Ambrosia call though
            string ambrosiaLogDirFromPTI = MyUtils.baseAmbrosiaPath + ConfigurationManager.AppSettings["AmbrosiaLogDirectory"] + "\\";
            string ambServiceLogPath = ambrosiaBaseLogDir + "\\";

            // Enables echoing the 'doWork' method call back to the client
            if ((bidi) && (instanceRole != JSPTI_ClientInstanceRole))
            {
                argString = argString + " -bd";
            }

            // set the -n and -eeb parameter only for non server
            if (instanceRole != JSPTI_ServerInstanceRole)
            {
                argString = argString + " -n=" + numRounds.ToString() + " -eeb=" + totalEchoBytes.ToString();
            }

            // set the -nhc and -efb for anything that is not client (server or combined)
            if (instanceRole != JSPTI_ClientInstanceRole)
            {
                argString = argString + " -nhc -efb=" + totalBytes.ToString();
            }

            // If passing zero then just use the default value.
            // Max Message Size
            if ((maxMessageSize > 0) && (instanceRole != JSPTI_ServerInstanceRole))
            {
                argString = argString + " -mms=" + maxMessageSize.ToString();
            }

            // bytes per round
            if ((bytesPerRound > 0) && (instanceRole != JSPTI_ServerInstanceRole))
            {
                argString = argString + " -bpr=" + bytesPerRound.ToString();
            }

            // batch size cutoff ... if 0 then use default
            if ((batchSizeCutoff > 0) && (instanceRole != JSPTI_ServerInstanceRole))
            {
                argString = argString + " -bsc=" + batchSizeCutoff.ToString();
            }

            // set the serverInstance if set (only used for client)
            if (serverInstanceName != "")
            {
                argString = argString + " -sin=" + serverInstanceName;
            }

            // if not in standard log place, then must be in InProc log location which is relative to PTI - safe assumption
/*  *#*#*# DELETE *#*#*
            if (Directory.Exists(ambrosiaBaseLogDir) == false)
            {
                ambrosiaBaseLogDir = MyUtils.baseAmbrosiaPath + ConfigurationManager.AppSettings["AmbrosiaLogDirectory"];
                ambrosiaLogDirFromPTI = "..\\..\\" + ambrosiaBaseLogDir + "\\";   // feels like there has to be better way of determining this - used for TTD
                ambServiceLogPath = "..\\..\\" + ambrosiaBaseLogDir + "\\";
            }
*/

            // used to get log file
            string ambrosiaFullLogDir = ambrosiaBaseLogDir + "\\" + testName + strLogFileInstanceRole + "_0";
            string startingChkPtVersionNumber = "1";

            // Get most recent version of log file and check point
            string actualLogFile = "";
            if (Directory.Exists(ambrosiaFullLogDir))
            {
                DirectoryInfo d = new DirectoryInfo(ambrosiaFullLogDir);
                FileInfo[] files = d.GetFiles().OrderBy(p => p.CreationTime).ToArray();

                // Where set what actual log file want to start with
                actualLogFile = files[0].Name.Replace("1", serverlognum.ToString());

            }
            else
            {
                Assert.Fail("<JS_VerifyTimeTravelDebugging> Unable to find Log directory: " + ambrosiaFullLogDir);
            }

            // determine if log or chkpt file
            if (actualLogFile.Contains("chkpt"))
            {
                int chkPtPos = actualLogFile.IndexOf("chkpt");
                startingChkPtVersionNumber = actualLogFile.Substring(chkPtPos + 5);
            }
            else
            {
                int LogPos = actualLogFile.IndexOf("log");
                startingChkPtVersionNumber = actualLogFile.Substring(LogPos + 3);
            }

            startingCheckPoint = startingCheckPoint + startingChkPtVersionNumber;  // used in verification of output log
            JS_UpdateJSConfigFile(JSConfig_debugStartCheckpoint, startingChkPtVersionNumber);
            JS_UpdateJSConfigFile(JSConfig_instanceName, testName + strLogFileInstanceRole.ToLower());  // need to update this so know where the log files are at

            int processID = MyUtils.LaunchProcess(workingDir, fileNameExe, argString, false, logOutputFileName_TestApp);
            if (processID <= 0)
            {
                MyUtils.FailureSupport("");
                Assert.Fail("<JS_VerifyTimeTravelDebugging> JS TestApp was not started.  ProcessID <=0 ");
            }

            // Give it a few seconds to start
            Thread.Sleep(3000);
            Application.DoEvents();  // if don't do this ... system sees thread as blocked thread and throws message.

            bool pass = true;

            if ((instanceRole == JSPTI_CombinedInstanceRole) || (instanceRole == ""))
            {
                // Combined Instance role puts client and server in one log file
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, totalBytes.ToString(), 15, false, testName, true, checkForDoneString);
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, successString, 2, false, testName, true, false);
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, allRoundsComplete, 1, false, testName, true, false);

                // Since client and server in same log file, have to check if bidi is here
                if (bidi == false)
                {
                    pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, successEchoString, 0, true, testName, false, false);
                    if (pass == true)
                        Assert.Fail("<JS_VerifyTimeTravelDebugging> Echoed string should NOT have been found in the output but it was.");
                }
                else // do echo string check if bidi
                    pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, successEchoString, 1, false, testName, true, false);

            }

            if (instanceRole == JSPTI_ServerInstanceRole)
            {
                // Verify the TTD outptut  of the server
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, bytesReceivedString, 10, false, testName, true);
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, successString, 1, false, testName, true);
            }

            if (instanceRole == JSPTI_ClientInstanceRole)
            {
                // Verify the data in the output file of the CLIENT - if NOT bidi the TTD won't work for client only any ways so can assume if doing it, then it is bidi
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, successEchoString, 10, false, testName, true, false);
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, allRoundsComplete, 1, false, testName, true, false);
            }

            if (specialVerifyString != "")  // used for special strings that are not generic enough to hard code and is more test specific
                pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, specialVerifyString, 1, false, testName, true, false);

            // double check to make sure actually TTD and not just normal run
            pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, argForTTD, 1, false, testName, true, false);
        }