示例#1
0
        private async Task ExecuteTestAgentRunAsync(TestAgentRunDto testAgentRun, int testAgentRunTimeout, CancellationTokenSource cancellationTokenSource)
        {
            _pluginService.ExecuteAllTestAgentPluginsPreTestRunLogic();

            testAgentRun.Status = TestAgentRunStatus.InProgress;
            await CreateEnvironmentVariablesForCustomArgumentsAsync(testAgentRun.TestRunId).ConfigureAwait(false);

            await _testAgentRunRepository.UpdateAsync(testAgentRun.TestAgentRunId, testAgentRun).ConfigureAwait(false);

            var testRun = await _testRunRepository.GetAsync(testAgentRun.TestRunId).ConfigureAwait(false);

            var tempExecutionFolder = _pathProvider.Combine(_pathProvider.GetTempFolderPath(), _guidService.NewGuid().ToString());
            var tempZipFileName     = _pathProvider.GetTempFileName();
            var testRunOutput       = await _testRunOutputServiceClient.GetTestRunOutputByTestRunIdAsync(testRun.TestRunId).ConfigureAwait(false);

            if (testRunOutput == null)
            {
                // DEBUG:
                await _testRunLogService.CreateTestRunLogAsync("The test run output cannot be null.", testAgentRun.TestRunId).ConfigureAwait(false);

                throw new ArgumentException("The test run output cannot be null.");
            }

            _fileProvider.WriteAllBytes(tempZipFileName, testRunOutput.TestOutputFilesPackage);
            _fileProvider.ExtractZip(tempZipFileName, tempExecutionFolder);
            var testRunTestsAssemblyPath = _pathProvider.Combine(tempExecutionFolder, testRun.TestAssemblyName);

            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            var testsResults = await _nativeTestsRunner.ExecuteTestsAsync(
                testRun.TestTechnology,
                testAgentRun.TestList,
                tempExecutionFolder,
                testAgentRun.TestRunId,
                testRunTestsAssemblyPath,
                testRun.TestAssemblyName,
                testRun.RunInParallel,
                testRun.NativeArguments,
                testAgentRunTimeout,
                testRun.IsTimeBasedBalance,
                testRun.SameMachineByClass,
                cancellationTokenSource).ConfigureAwait(false);

            var retriedTestResults = string.Empty;

            if (testRun.RetriesCount > 0)
            {
                retriedTestResults = await _nativeTestsRunner.ExecuteTestsWithRetryAsync(
                    testRun.TestTechnology,
                    testsResults,
                    testAgentRun.TestList,
                    tempExecutionFolder,
                    testAgentRun.TestRunId,
                    testRunTestsAssemblyPath,
                    testRun.TestAssemblyName,
                    testRun.RunInParallel,
                    testRun.NativeArguments,
                    testAgentRunTimeout,
                    testRun.RetriesCount,
                    testRun.Threshold,
                    testRun.IsTimeBasedBalance,
                    testRun.SameMachineByClass,
                    cancellationTokenSource).ConfigureAwait(false);
            }

            if (cancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            await CompleteTestAgentRunAsync(testAgentRun.TestAgentRunId, testsResults, retriedTestResults).ConfigureAwait(false);

            _pluginService.ExecuteAllTestAgentPluginsPostTestRunLogic();

            DeleteTempExecutionFolder(tempExecutionFolder);
        }