public void RunAllEntryTests() { TestsQueue testsQueue = _webData.GetFirstTestQueue(_client); Tests testProcess = new Tests() { GameId = testsQueue.GameId }; try { while (testsQueue != null) { lock (_sync) { testProcess.GameId = testsQueue.GameId; RunSingleEntryTest(testsQueue, testProcess); } DeleteFolder(); testsQueue = _webData.GetFirstTestQueue(_client); } SendEmail(); _webData.StopAutomatedTestingEC2(_client); } catch (Exception e) { _logger.LogError(e.Message, e); _webData.DeleteTestQueue((int)testsQueue.GameId, _client); _webData.PutGames(new GamesEntry() { GameId = testsQueue.GameId, GameStatus = "p" }, _client); _webData.PutTests(testProcess, _client); _webData.PostTestingLog(new TestingLog() { GameId = testsQueue.GameId, TestlogAttempt = -1, TestlogDatetimeUtc = DateTime.Now, TestlogLog = "There was an error with the tests and the program has crashed due to: " + e.Message + " It will attempt to shutdown." }, _client); SendEmail(); DeleteFolder(); _webData.StopAutomatedTestingEC2(_client); } }
public void RunSingleEntryTest(TestsQueue testsQueue, Tests testProcess) { try { while (testsQueue.RetryCount < 3) { TestingLog testLog = new TestingLog(); _webData.PutTestsQueue(testsQueue, _client); testLog.TestlogAttempt = (int)testsQueue.RetryCount; testLog.GameId = (int)testsQueue.GameId; GamesEntry myGame = _webData.GetGamesByID(testsQueue.GameId, _client); //Retry to pull game if it failed the first time if (myGame == null) { testProcess.TestOpens = false; testProcess.Test5min = false; testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; continue; } string debugKey = "public/" + myGame.GamePath; fileLocation = _s3Data.ReadObjectDataAsync(debugKey).Result; //Point variable to folder which contains .exe file string subFileLocation = FindSubDir(fileLocation); //Store list of names of files within game folder testProcess.TestFolderFileNames = FolderFileNames(subFileLocation); //Find .exe file path string[] exeFiles = FindExe(subFileLocation); //Store number of exe files within game folder testProcess.TestNumExeFiles = exeFiles.Length; gameProcess = new Process(); //start .exe, check to see if it started testProcess.TestOpens = StartFile(exeFiles[0]); //Retry tests if process does not start if (!(bool)testProcess.TestOpens) { testProcess.Test5min = false; testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game Failed Start Test"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Check to see if game still running after 5 min testProcess.Test5min = SleepFile(exeFiles[0]); //Retry tests if process does not stay open for 5 min if ((bool)!testProcess.Test5min) { testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game Failed Sleep Test"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Store memory usage by game process testProcess.TestAverageRam = RamFile(); //Retry tests if the program is unable to record the game's RAM usage if (testProcess.TestAverageRam == null) { testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game Average RAM Test Failed"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Store memory usage by game process testProcess.TestPeakRam = RamFile(); //Retry tests if the program is unable to record the game's RAM usage if (testProcess.TestPeakRam == null) { testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game Peak RAM Test Failed"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Test whether game will close on "3" key press int i = CloseOn3(exeFiles[0]); if (i == 0) { testProcess.TestCloseOn3 = true; } else if (i == 1) { testProcess.TestCloseOn3 = false; } //Retry tests if the program is unable to restart after passing "3" test else if (i == 2) { testProcess.TestOpens = false; testProcess.Test5min = false; testProcess.TestAverageRam = null; testProcess.TestPeakRam = null; testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game passed 'close on 3' test but failed to restart"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Log if game did not shut down after "3" press if ((bool)!testProcess.TestCloseOn3) { testLog.TestlogLog = "Game failed 'close on 3' test"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; } //Test whether game will close on "Escape" key press i = EscapeFile(exeFiles[0]); //Log if game did not shut down after "Escape" press if (i == 0) { testProcess.TestCloseOnEscape = true; } else if (i == 1) { testProcess.TestCloseOnEscape = false; } //Retry tests if the program is unable to restart after passing "3" test else if (i == 2) { testProcess.TestOpens = false; testProcess.Test5min = false; testProcess.TestAverageRam = null; testProcess.TestPeakRam = null; testProcess.TestCloseOn3 = false; testProcess.TestCloseOnEscape = false; testProcess.TestCloses = false; testLog.TestlogLog = "Game passed 'close on Escape' test but failed to restart"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //Log if game did not shut down after "3" press if ((bool)!testProcess.TestCloseOnEscape) { testLog.TestlogLog = "Game failed 'close on Escape' test"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; } //stop .exe, check to see if it stopped testProcess.TestCloses = StopFile(exeFiles[0]); if ((bool)!testProcess.TestCloses) { testLog.TestlogLog = "Game Failed Stop Test"; testLog.TestlogDatetimeUtc = DateTime.UtcNow; _webData.PostTestingLog(testLog, _client); continue; } //If all tests passed, update game object and stop rechecking if ((bool)testProcess.TestOpens && (bool)testProcess.Test5min && (bool)testProcess.TestCloses) { myGame.GameReviewDateUtc = DateTime.UtcNow; myGame.GameStatus = "p"; _webData.PutGames(myGame, _client); break; } } //Delete game from test queue and push the test results to database _webData.DeleteTestQueue(testsQueue.GameId, _client); _webData.PutTests(testProcess, _client); } catch (Exception e) { _logger.LogError(e.Message, e); } }