Exemple #1
0
 /// <inheritdoc cref="IDisposable.Dispose" />
 public void Dispose()
 {
     _telemetrySession?.Dispose();
 }
        public void Dispose()
        {
#if false
            From    : Brad White <*****@*****.**>
            Sent    : Wednesday, February 5, 2020 6 : 08 PM
            To      : Calvin Hsia <*****@*****.**>
            Subject : RE : Get Run ID from test

             From within an Apex / DTE test how do
                I get something like “Release - 800” from the screenshot below?
                I would advise against adding dependencies on Azure DevOps to test code.

                We push our telemetry in one of two ways :
                1.      Service hook that calls an Azure Function
                2.      Script in the release that runs after test execution

                For you, I’d recommend #2. Add a script that runs after the tests complete.To get the run ID, you can use $(testrunid), which gets set by the Visual Studio Test task after the run has completed.
#endif

            var duration = (DateTime.Now - _startTime);
            var secsPerIteration = duration.TotalSeconds / stressUtilOptions.NumIterations;
            Logger.LogMessage($"Number of Seconds/Iteration = {secsPerIteration:n1}");
            dictTelemetryProperties["IterationsPerSecond"] = secsPerIteration;
            dictTelemetryProperties["Duration"]            = duration.TotalSeconds;

            dictTelemetryProperties["GoneQuietAvg"]        = (double)this._GoneQuietSamplesTaken / stressUtilOptions.NumIterations;
            dictTelemetryProperties["IterationsGoneQuiet"] = this._IterationsGoneQuiet;
            dictTelemetryProperties["NumIterations"]       = stressUtilOptions.NumIterations;
            dictTelemetryProperties["TestName"]            = this.TestName;
            dictTelemetryProperties["MachineName"]         = Environment.GetEnvironmentVariable("COMPUTERNAME");
            dictTelemetryProperties["TargetProcessName"]   = Path.GetFileNameWithoutExtension(LstPerfCounterData[0].ProcToMonitor.MainModule.FileName);
            var fileVersion = LstPerfCounterData[0].ProcToMonitor.MainModule.FileVersionInfo.FileVersion;
            var lastSpace   = fileVersion.LastIndexOf(" ");
            var branchName  = string.Empty;
            if (lastSpace > 0)
            {
                branchName = fileVersion.Substring(lastSpace + 1);
            }
            dictTelemetryProperties["TargetProcessVersion"] = fileVersion;
            dictTelemetryProperties["BranchName"]           = branchName;
            if (stressUtilOptions.TypesToReportStatisticsOn != null)
            {
                dictTelemetryProperties["TypesToReportStatisticsOn"] = stressUtilOptions.TypesToReportStatisticsOn;
            }

            //            WriteResultsToXML(Path.Combine(ResultsFolder, _xmlResultFileName));
            if (this.testContext != null)
            {
                if (Logger is Logger myLogger)
                {
                    var sb = new StringBuilder();
                    foreach (var str in myLogger._lstLoggedStrings)
                    {
                        sb.AppendLine(str);
                    }
                    var filename = Path.Combine(ResultsFolder, $"StressTestLog.log");
                    File.WriteAllText(filename, sb.ToString());
                    lstFileResults.Add(new FileResultsData()
                    {
                        filename = filename, description = "Stress Test Log"
                    });
                }
                foreach (var fileresult in lstFileResults)
                {
                    this.testContext.AddResultFile(fileresult.filename);
                }
            }
            if (stressUtilOptions.SendTelemetry)
            {
                PostTelemetryEvent("devdivstress/stresslib/leakresult", dictTelemetryProperties);
                if (Process.GetCurrentProcess().ProcessName != "devenv") // if we're running as a VSIX
                {
                    if (telemetrySession != null)
                    {
                        telemetrySession.Dispose();
                        telemetrySession = null;
                    }
                }
            }
        }