private void SendTestResults(CiEvent ciEvent)
        {
            try
            {
                DateTime start = DateTime.Now;
                string   msg   = "";
                if (_octaneApis.IsTestResultRelevant(ciEvent.Project))
                {
                    var run = _tfsApis.GetRunForBuild(ciEvent.BuildInfo.CollectionName, ciEvent.BuildInfo.Project, ciEvent.BuildInfo.BuildId);
                    if (run == null)
                    {
                        msg = "Run was not created for build. No test results.";
                    }
                    else
                    {
                        var testResults = _tfsApis.GetTestResultsForRun(ciEvent.BuildInfo.CollectionName, ciEvent.BuildInfo.Project, run.Id.ToString());
                        OctaneTestResult octaneTestResult = OctaneTestResutsUtils.ConvertToOctaneTestResult(_octaneApis.PluginInstanceId, ciEvent.Project, ciEvent.BuildId, testResults, run.WebAccessUrl);
                        _octaneApis.SendTestResults(octaneTestResult);
                        msg = $"TestResults are sent ({octaneTestResult.TestRuns.Count} tests)";
                    }
                }
                else
                {
                    msg = "GetTestResultRelevant = false";
                }

                DateTime end = DateTime.Now;
                Log.Info($"Build {ciEvent.BuildInfo} - {msg}. Handling time is {(long)((end - start).TotalMilliseconds)} ms.");
            }
            catch (Exception ex)
            {
                Log.Error($"Build {ciEvent.BuildInfo} : error in SendTestResults : {ex.Message}", ex);
                throw ex;
            }
        }
示例#2
0
        public void SendTestResults(OctaneTestResult octaneTestResult)
        {
            bool skipErrors = false;
            var  baseUri    = $"{INTERNAL_API}{_connectionDetails.SharedSpace}{ANALYTICS_TEST_RESULTS}?skip-errors={skipErrors.ToString().ToLower()}";

            String          xml = OctaneTestResutsUtils.SerializeToXml(octaneTestResult);
            ResponseWrapper res = _restConnector.ExecutePost(baseUri, null, xml,
                                                             RequestConfiguration.Create().SetGZipCompression(true).AddHeader("ContentType", "application/xml"));

            ValidateExpectedStatusCode(res, HttpStatusCode.Accepted);
        }
示例#3
0
        public static string SerializeToXml(OctaneTestResult octaneTestResult)
        {
            var xmlSerializer = new XmlSerializer(typeof(OctaneTestResult));

            using (StringWriter textWriter = new Utf8StringWriter())
            {
                var ns = new XmlSerializerNamespaces();
                ns.Add("", "");
                xmlSerializer.Serialize(textWriter, octaneTestResult, ns);
                string result = textWriter.ToString();
                Log.Debug(result);

                return(result);
            }
        }
示例#4
0
        public static OctaneTestResult ConvertToOctaneTestResult(string serverId, string projectCiId, string buildCiId, IList <TfsTestResult> testResults, string runWebAccessUrl)
        {
            if (testResults.Count <= 0)
            {
                return(null);
            }
            //Serialization prepare
            var octaneTestResult = new OctaneTestResult();
            var build            = testResults[0].Build;
            var project          = testResults[0].Project;

            octaneTestResult.Build = OctaneTestResultBuild.Create(serverId, buildCiId, projectCiId);

            /*octaneTestResult.TestFields = new List<OctaneTestResultTestField>(new[] {
             *          OctaneTestResultTestField.Create(OctaneTestResultTestField.TEST_LEVEL_TYPE, "UnitTest")
             *      });*/

            octaneTestResult.TestRuns = new List <OctaneTestResultTestRun>();
            foreach (var testResult in testResults)
            {
                var run = new OctaneTestResultTestRun();
                if (testResult.AutomatedTestType.Equals("JUnit"))
                {
                    var testNameParts = testResult.AutomatedTestStorage.Split('.');
                    run.Name    = testResult.AutomatedTestName;
                    run.Class   = testNameParts[testNameParts.Length - 1];
                    run.Package = String.Join(".", new ArraySegment <String>(testNameParts, 0, testNameParts.Length - 1));
                }
                else // UnitTest
                {
                    var testNameParts = testResult.AutomatedTestName.Split('.');
                    run.Name    = testNameParts[testNameParts.Length - 1];
                    run.Class   = testNameParts[testNameParts.Length - 2];
                    run.Package = String.Join(".", new ArraySegment <String>(testNameParts, 0, testNameParts.Length - 2));
                    run.Module  = Path.GetFileNameWithoutExtension(testResult.AutomatedTestStorage);
                }


                run.Duration = (long)testResult.DurationInMs;
                run.Status   = testResult.Outcome;
                if (run.Status.Equals("NotExecuted"))
                {
                    run.Status = "Skipped";
                }

                if (run.Status.Equals("Failed"))
                {
                    if (testResult.FailureType == "None" || String.IsNullOrEmpty(testResult.FailureType))
                    {
                        testResult.FailureType = FindExceptionName(testResult);
                    }

                    run.Error = OctaneTestResultError.Create(testResult.FailureType, testResult.ErrorMessage, testResult.StackTrace);
                }

                run.Started = OctaneUtils.ConvertToOctaneTime(testResult.StartedDate);

                if (!string.IsNullOrEmpty(runWebAccessUrl))
                {
                    //Run WebAccessUrl        http://berkovir:8080/tfs/DefaultCollection/Test2/_TestManagement/Runs#runId=8&_a=runCharts
                    //Run Result WebAccessUrl http://berkovir:8080/tfs/DefaultCollection/Test2/_TestManagement/Runs#runId=8&_a=resultSummary&resultId=100000
                    run.ExternalReportUrl = runWebAccessUrl.Replace("_a=runCharts", ($"_a=resultSummary&resultId={testResult.Id}"));
                }

                octaneTestResult.TestRuns.Add(run);
            }
            return(octaneTestResult);
        }