public async Task ReturnNoTestAgents_When_NoTestAgentsExists() { // Arrange var testAgents = TestAgentFactory.CreateEmpty(); _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents)); // Act var actualTestAgents = await _testAgentsService.GetAllActiveTestAgentsByTagAsync(_agentTag); // Assert Assert.That(actualTestAgents, Is.Empty); }
public async Task <bool> ExecuteAsync(TestRunSettings testRunSettings) { if (!_pathProvider.IsFilePathValid(testRunSettings.ResultsFilePath)) { throw new ArgumentException($"The specified test results file path is not valid. Specified path = {testRunSettings.ResultsFilePath}"); } _pluginService.ExecuteAllTestRunnerPluginsPreTestRunLogic(); await _testRunsCleanerServiceClient.DeleteOldTestRunsDataAsync(); await _testCasesHistoryService.DeleteOlderTestCasesHistoryAsync(); var activeTestAgents = await _testAgentService.GetAllActiveTestAgentsByTagAsync(testRunSettings.AgentTag); await _testAgentService.SetAllActiveAgentsToVerifyTheirStatusAsync(testRunSettings.AgentTag); await _testAgentService.WaitAllActiveAgentsToVerifyTheirStatusAsync(activeTestAgents); var availableTestAgents = await _testAgentService.GetAllActiveTestAgentsByTagAsync(testRunSettings.AgentTag); bool wasSuccessfulRun = false; if (availableTestAgents.Count > 0) { var tempFilePath = _pathProvider.GetTempFileName(); _fileProvider.Delete(tempFilePath); _fileProvider.CreateZip(testRunSettings.OutputFilesLocation, tempFilePath); var zipData = _fileProvider.ReadAllBytes(tempFilePath); var testRunId = await _testRunProvider.CreateNewTestRunAsync(_pathProvider.GetFileName(testRunSettings.TestLibraryPath), zipData, testRunSettings.RetriesCount, testRunSettings.Threshold, testRunSettings.RunInParallel, testRunSettings.MaxParallelProcessesCount, testRunSettings.NativeArguments, testRunSettings.TestTechnology, testRunSettings.TimeBasedBalance, testRunSettings.CustomArguments); _testCasesProvider = _pluginService.GetNativeTestsRunnerTestCasesPluginService(testRunSettings.TestTechnology); var allTestCases = _testCasesProvider.ExtractAllTestCasesFromTestLibrary(testRunSettings.TestLibraryPath); var filteredTestCases = _testCasesFilterService.FilterCases(allTestCases, testRunSettings.TestsFilter); var distributedTestsLists = testRunSettings.TimeBasedBalance ? await _testsTimesBasedDistributeService.GenerateDistributionListsAsync(availableTestAgents.Count, filteredTestCases) : _testCountsBasedDistributeService.GenerateDistributionLists(availableTestAgents.Count, filteredTestCases); var testAgentRuns = await _testAgentRunProvider.CreateNewTestAgentRunsAsync(testRunId, availableTestAgents, distributedTestsLists); try { // TODO: pass ExecutionFrequency from args console? await _testAgentRunProvider.WaitForTestAgentRunsToFinishAsync(testAgentRuns, testRunSettings.TestRunTimeout, ExecutionFrequency); // DEBUG: ////_consoleProvider.WriteLine("AFTER WaitForTestAgentRunsToFinishAsync"); _consoleProvider.WriteLine(TestAgentRunsHasFinished); } catch (TimeoutException) { _consoleProvider.WriteLine(string.Format(TestRunHasTimedOut, testRunSettings.TestRunTimeout)); await _testAgentRunProvider.AbortAllTestAgentRunsInTestRunAsync(testRunId); } var areThereAbortedTestAgentRuns = await _testAgentRunProvider.AreThereAbortedTestAgentRunsAsync(testRunId); if (!areThereAbortedTestAgentRuns) { // DEBUG: ////_consoleProvider.WriteLine("START COMPLEETING TEST RUN"); await _testRunProvider.CompleteTestRunAsync(testRunId, TestRunStatus.Completed); wasSuccessfulRun = true; // DEBUG: _consoleProvider.WriteLine("TEST RUN COMPLETED"); await _testResultsService.SaveTestResultsForCurrentRunAsync(testRunSettings.TestTechnology, testRunSettings.ResultsFilePath, testRunSettings.RetriedResultsFilePath, testRunId); try { await _testRunsCleanerServiceClient.DeleteOldTestRunDataByTestRunIdAsync(testRunId); } catch (Exception e) { _consoleProvider.WriteLine(e.ToString()); } } else { _consoleProvider.WriteLine("Test Run Aborted!"); await _testRunProvider.CompleteTestRunAsync(testRunId, TestRunStatus.Aborted); } } else { _consoleProvider.WriteLine(NoTestAgentsAreAvailable); } _pluginService.ExecuteAllTestRunnerPluginsPostTestRunLogic(); return(wasSuccessfulRun); }