Example #1
0
        private void EventsOnSessionEnd(object sender, SessionEndEventArgs e)
        {
            try
            {
                if (_coverageFlushed)
                {
                    return;
                }

                var mutationCoverage = Utils.ReadMutationCoverageFile();

                // Filter out functions that are not tests
                mutationCoverage.Coverage = mutationCoverage.Coverage
                                            .Where(pair => _testNames.Contains(pair.Key))
                                            .ToDictionary(pair => pair.Key, pair => pair.Value);

                Utils.WriteMutationCoverageFile(mutationCoverage);

                _coverageFlushed = true;
            }
            catch (Exception ex)
            {
                _logger.LogError(context.SessionDataCollectionContext, $"Test Session Exception: {ex}");
            }

            _logger.LogWarning(context.SessionDataCollectionContext, "Coverage Test Session Finished");
        }
        /// <summary>
        /// SessionEnd event handler
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void OnSessionEnd(object sender, SessionEndEventArgs e)
        {
            try
            {
                _eqtTrace.Verbose("{0}: SessionEnd received", CoverletConstants.DataCollectorName);

                // Get coverage reports
                IEnumerable <(string report, string fileName)> coverageReports = _coverageManager?.GetCoverageReports();

                if (coverageReports != null && coverageReports.Count() > 0)
                {
                    // Send result attachments to test platform.
                    using (var attachmentManager = new AttachmentManager(_dataSink, _dataCollectionContext, _logger, _eqtTrace, _countDownEventFactory.Create(coverageReports.Count(), TimeSpan.FromSeconds(30))))
                    {
                        foreach ((string report, string fileName) in coverageReports)
                        {
                            attachmentManager.SendCoverageReport(report, fileName);
                        }
                    }
                }
                else
                {
                    _eqtTrace.Verbose("{0}: No coverage reports specified", CoverletConstants.DataCollectorName);
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.ToString());
                this.Dispose(true);
            }
        }
Example #3
0
        private void SessionEnded_Handler(object sender, SessionEndEventArgs args)
        {
            //logger.LogError(this.context.SessionDataCollectionContext, new Exception("my exception"));
            //logger.LogWarning(this.context.SessionDataCollectionContext, "my arning");
            //logger.LogException(context.SessionDataCollectionContext, new Exception("abc"), DataCollectorMessageLevel.Error);

            this.logger.LogWarning(this.context.SessionDataCollectionContext, "SessionEnded");
        }
        private void OnSessionEnd(object sender, SessionEndEventArgs e)
        {
            Trace.TraceInformation("Session ended");

            mSessionEnded();
            mFileWriterThing.LastOrDefaultAsync().Wait();
            mDataSink.SendFileAsync(e.Context, mDataFilePath, true);
        }
Example #5
0
        private void SessionEnded_Handler(object sender, SessionEndEventArgs e)
        {
            string tmpAttachment = Path.Combine(_tempDirectoryPath, Guid.NewGuid().ToString("N"), "DataCollectorAttachmentProcessor_1.txt");

            Directory.CreateDirectory(Path.GetDirectoryName(tmpAttachment));
            File.WriteAllText(tmpAttachment, $"SessionEnded_Handler_{Guid.NewGuid():N}");
            _dataCollectionSink.SendFileAsync(_context.SessionDataCollectionContext, tmpAttachment, true);
        }
Example #6
0
        public void SessionEndShouldStopVanguard()
        {
            var sessionEndEventArgs = new SessionEndEventArgs();

            this.collectorImpl.SessionEnd(null, sessionEndEventArgs);

            this.vanguardMock.Verify(v => v.Stop());
        }
Example #7
0
        /// <summary>
        /// Called when Session End event is invoked
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">SessionEndEventArgs</param>
        private void SessionEnded_Handler(object sender, SessionEndEventArgs args)
        {
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Blame Collector : Session End");
            }

            try
            {
                // If the last test crashes, it will not invoke a test case end and therefore
                // In case of crash testStartCount will be greater than testEndCount and we need to write the sequence
                // And send the attachment
                if (this.testStartCount > this.testEndCount)
                {
                    var filepath = Path.Combine(this.GetResultsDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid);
                    filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath);
                    var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
                    this.dataCollectionSink.SendFileAsync(fileTranferInformation);
                }

                if (this.processDumpEnabled)
                {
                    // If there was a test case crash or if we need to collect dump on process exit.
                    if (this.testStartCount > this.testEndCount || this.collectDumpAlways)
                    {
                        try
                        {
                            var dumpFile = this.processDumpUtility.GetDumpFile();
                            if (!string.IsNullOrEmpty(dumpFile))
                            {
                                var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, dumpFile, true);
                                this.dataCollectionSink.SendFileAsync(fileTranferInformation);
                            }
                            else
                            {
                                EqtTrace.Warning("BlameCollector.SessionEnded_Handler: blame:CollectDump was enabled but dump file was not generated.");
                                this.logger.LogWarning(args.Context, Resources.Resources.ProcDumpNotGenerated);
                            }
                        }
                        catch (FileNotFoundException ex)
                        {
                            EqtTrace.Warning(ex.Message);
                            this.logger.LogWarning(args.Context, ex.Message);
                        }
                    }
                }
            }
            finally
            {
                // Attempt to terminate the proc dump process if proc dump was enabled
                if (this.processDumpEnabled)
                {
                    this.processDumpUtility.TerminateProcess();
                }

                this.DeregisterEvents();
            }
        }
Example #8
0
        public void SessionEndShouldSendCoverageFile()
        {
            string tempFile            = Path.GetTempFileName();
            var    sessionEndEventArgs = new SessionEndEventArgs();

            this.fileHelperMock.Setup(f => f.Exists(It.IsAny <string>())).Returns(true);
            this.collectorImpl.SessionEnd(null, sessionEndEventArgs);

            this.dataCollectionSinkMock.Verify(s => s.SendFileAsync(It.IsAny <DataCollectionContext>(), It.IsAny <string>(), false));
        }
Example #9
0
        private void OnSessionEnd(object sender, SessionEndEventArgs e)
        {
            ValidateArg.NotNull(e, "SessionEndEventArgs");
            ValidateArg.NotNull(e.Context, "SessionEndEventArgs.Context");

            if (EqtTrace.IsVerboseEnabled)
            {
                EqtTrace.Verbose("EventLogDataCollector: SessionEnd received");
            }

            this.WriteCollectedEventLogEntries(e.Context, true, TimeSpan.MaxValue, DateTime.Now);
        }
Example #10
0
        /// <inheritdoc/>
        public Collection <AttachmentSet> SessionEnded(bool isCancelled = false)
        {
            // Return null if datacollection is not enabled.
            if (!this.isDataCollectionEnabled)
            {
                return(new Collection <AttachmentSet>());
            }

            if (isCancelled)
            {
                this.attachmentManager.Cancel();
                return(new Collection <AttachmentSet>());
            }

            var endEvent = new SessionEndEventArgs(this.dataCollectionEnvironmentContext.SessionDataCollectionContext);

            this.SendEvent(endEvent);

            List <AttachmentSet> result = new List <AttachmentSet>();

            try
            {
                result = this.attachmentManager.GetAttachments(endEvent.Context);
            }
            catch (Exception ex)
            {
                if (EqtTrace.IsErrorEnabled)
                {
                    EqtTrace.Error("DataCollectionManager.SessionEnded: Failed to get attachments : {0}", ex.Message);
                }

                return(new Collection <AttachmentSet>(result));
            }

            foreach (var entry in result)
            {
                foreach (var file in entry.Attachments)
                {
                    if (EqtTrace.IsVerboseEnabled)
                    {
                        EqtTrace.Verbose(
                            "Run Attachment Description: Collector:'{0}'  Uri:'{1}'  Description:'{2}' Uri:'{3}' ",
                            entry.DisplayName,
                            entry.Uri,
                            file.Description,
                            file.Uri);
                    }
                }
            }

            return(new Collection <AttachmentSet>(result));
        }
        public void RaiseEventsShouldRaiseEventsIfSessionEndEventArgsIsPassed()
        {
            this.isEventRaised = false;
            var testCase = new TestCase();

            this.context = new DataCollectionContext(testCase);

            this.events.SessionEnd += this.SessionEndMessageHandler;
            var eventArgs = new SessionEndEventArgs(this.context);

            this.events.RaiseEvent(eventArgs);

            Assert.IsTrue(this.isEventRaised);
        }
Example #12
0
        private void EventsOnSessionEnd(object sender, SessionEndEventArgs e)
        {
            try
            {
                var serialized = _testResults.Serialize();
                File.WriteAllBytes(TestRunnerConstants.TestsFileName, serialized);
            }
            catch (Exception)
            {
                _logger.LogError(context.SessionDataCollectionContext, "Test Session Exception: {ex}");
            }

            _logger.LogWarning(context.SessionDataCollectionContext, "Test Session Finished");
        }
 void SessionEnded_Handler(object sender, SessionEndEventArgs e)
 {
     clocks.TryGetValue($"{e.Context?.SessionId?.Id}", out Stopwatch clock);
     log.Value.Log(new
     {
         Name      = "TestSessionEnded",
         RequestId = BuildArn ?? $"{e.Context?.SessionId?.Id}",
         Response  = new
         {
             StatusCode      = 200,
             RequestDuration = clock.Elapsed.TotalMilliseconds
         }
     });
     log2.LogWarning(e.Context, "SessionEnded");
 }
 private void Events_SessionEnd(object sender, SessionEndEventArgs e)
 {
     try
     {
         foreach (var file in Directory.GetFiles(_traceDirectory))
         {
             _logger.LogWarning(e.Context, $"Saving event pipe session: {file}");
             _dataSink.SendFileAsync(e.Context, file, deleteFile: true);
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(e.Context, "Error during SessionEnd", ex);
     }
 }
        /// <summary>
        /// SessionEnd event handler
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void OnSessionEnd(object sender, SessionEndEventArgs e)
        {
            try
            {
                _eqtTrace.Verbose("{0}: SessionEnd received", CoverletConstants.DataCollectorName);

                // Get coverage reports
                string coverageReport = _coverageManager?.GetCoverageReport();

                // Send result attachments to test platform.
                var attachmentManager = new AttachmentManager(_dataSink, _dataCollectionContext, _logger, _eqtTrace, this.GetReportFileName());
                attachmentManager?.SendCoverageReport(coverageReport);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.ToString());
                this.Dispose(true);
            }
        }
Example #16
0
        /// <summary>
        /// Called when Session End event is invoked
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">SessionEndEventArgs</param>
        private void SessionEnded_Handler(object sender, SessionEndEventArgs args)
        {
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Blame Collector : Session End");
            }

            // If the last test crashes, it will not invoke a test case end and therefore
            // In case of crash testStartCount will be greater than testEndCount and we need to write the sequence
            // And send the attachment
            if (this.testStartCount > this.testEndCount)
            {
                var filepath = Path.Combine(this.GetResultsDirectory(), Constants.AttachmentFileName);
                filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, filepath);
                var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
                this.dataCollectionSink.SendFileAsync(fileTranferInformation);
            }

            this.DeregisterEvents();
        }
Example #17
0
        /// <inheritdoc/>
        public Collection <AttachmentSet> SessionEnded(bool isCancelled = false)
        {
            // Return null if datacollection is not enabled.
            if (!this.isDataCollectionEnabled)
            {
                return(new Collection <AttachmentSet>());
            }

            if (isCancelled)
            {
                this.attachmentManager.Cancel();
                return(new Collection <AttachmentSet>());
            }

            var endEvent = new SessionEndEventArgs(this.dataCollectionEnvironmentContext.SessionDataCollectionContext);

            this.SendEvent(endEvent);

            var result = new List <AttachmentSet>();

            try
            {
                result = this.attachmentManager.GetAttachments(endEvent.Context);
            }
            catch (Exception ex)
            {
                if (EqtTrace.IsErrorEnabled)
                {
                    EqtTrace.Error("DataCollectionManager.SessionEnded: Failed to get attachments : {0}", ex);
                }

                return(new Collection <AttachmentSet>(result));
            }

            if (EqtTrace.IsVerboseEnabled)
            {
                this.LogAttachments(result);
            }

            return(new Collection <AttachmentSet>(result));
        }
 private void OnSessionEnd(object sender, SessionEndEventArgs e)
 {
     _nyanCat.Stop();
 }
 private void OnSessionEnd(object sender, SessionEndEventArgs e)
 {
     _nyanCat.Stop();
 }
Example #20
0
 /// <inheritdoc />
 public void SendTestSessionEnd(SessionEndEventArgs e)
 {
     this.communicationManager.SendMessage(MessageType.SessionEnd, e);
 }
Example #21
0
        /// <summary>
        /// Called when Session End event is invoked
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">SessionEndEventArgs</param>
        private void SessionEndedHandler(object sender, SessionEndEventArgs args)
        {
            this.ResetInactivityTimer();

            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Blame Collector : Session End");
            }

            try
            {
                // If the last test crashes, it will not invoke a test case end and therefore
                // In case of crash testStartCount will be greater than testEndCount and we need to write the sequence
                // And send the attachment
                if (this.testStartCount > this.testEndCount)
                {
                    var filepath = Path.Combine(this.GetTempDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid);

                    filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath);
                    var fti = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
                    this.dataCollectionSink.SendFileAsync(fti);
                }
                else
                {
                    if (this.collectProcessDumpOnTestHostHang)
                    {
                        this.logger.LogWarning(this.context.SessionDataCollectionContext, Resources.Resources.NotGeneratingSequenceFile);
                    }
                }

                if (this.uploadDumpFiles)
                {
                    try
                    {
                        var dumpFiles = this.processDumpUtility.GetDumpFiles(warnOnNoDumpFiles: this.collectDumpAlways);
                        foreach (var dumpFile in dumpFiles)
                        {
                            if (!string.IsNullOrEmpty(dumpFile))
                            {
                                try
                                {
                                    var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, dumpFile, true);
                                    this.dataCollectionSink.SendFileAsync(fileTranferInformation);
                                }
                                catch (FileNotFoundException ex)
                                {
                                    EqtTrace.Warning(ex.ToString());
                                    this.logger.LogWarning(args.Context, ex.ToString());
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException ex)
                    {
                        EqtTrace.Warning(ex.ToString());
                        this.logger.LogWarning(args.Context, ex.ToString());
                    }
                }
                else
                {
                    EqtTrace.Info("BlameCollector.CollectDumpAndAbortTesthost: Custom path to dump directory was provided via VSTEST_DUMP_PATH. Skipping attachment upload, the caller is responsible for collecting and uploading the dumps themselves.");
                }
            }
            finally
            {
                // Attempt to terminate the proc dump process if proc dump was enabled
                if (this.collectProcessDumpOnTrigger)
                {
                    this.processDumpUtility.DetachFromTargetProcess(this.testHostProcessId);
                }

                this.DeregisterEvents();
            }
        }
 /// <inheritdoc />
 public void RaiseSessionEnd(SessionEndEventArgs e)
 {
     this.SessionEnd.SafeInvoke(this, e, "DataCollectionTestCaseEventManager.RaiseSessionEnd");
 }
 private void SessionEndMessageHandler(object sender, SessionEndEventArgs e)
 {
     this.isEventRaised = true;
 }
Example #24
0
        /// <summary>
        /// Called when Session End event is invoked
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="args">SessionEndEventArgs</param>
        private void SessionEndedHandler(object sender, SessionEndEventArgs args)
        {
            this.ResetInactivityTimer();

            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Blame Collector : Session End");
            }

            try
            {
                // If the last test crashes, it will not invoke a test case end and therefore
                // In case of crash testStartCount will be greater than testEndCount and we need to write the sequence
                // And send the attachment
                if (this.testStartCount > this.testEndCount)
                {
                    var filepath = Path.Combine(this.GetTempDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid);

                    filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath);
                    var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
                    this.dataCollectionSink.SendFileAsync(fileTranferInformation);
                }

                if (this.collectProcessDumpOnTrigger)
                {
                    // If there was a test case crash or if we need to collect dump on process exit.
                    //
                    // Do not try to collect dump when we already collected one from the hang dump
                    // we won't dump the killed process again and that would just show a warning on the command line
                    if ((this.testStartCount > this.testEndCount || this.collectDumpAlways) && !this.dumpWasCollectedByHangDumper)
                    {
                        try
                        {
                            var dumpFile = this.processDumpUtility.GetDumpFile();
                            if (!string.IsNullOrEmpty(dumpFile))
                            {
                                var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, dumpFile, true);
                                this.dataCollectionSink.SendFileAsync(fileTranferInformation);
                            }
                            else
                            {
                                EqtTrace.Warning("BlameCollector.SessionEndedHandler: blame:CollectDump was enabled but dump file was not generated.");
                                this.logger.LogWarning(args.Context, Resources.Resources.ProcDumpNotGenerated);
                            }
                        }
                        catch (FileNotFoundException ex)
                        {
                            EqtTrace.Warning(ex.ToString());
                            this.logger.LogWarning(args.Context, ex.ToString());
                        }
                    }
                }
            }
            finally
            {
                // Attempt to terminate the proc dump process if proc dump was enabled
                if (this.collectProcessDumpOnTrigger)
                {
                    this.processDumpUtility.DetachFromTargetProcess(this.testHostProcessId);
                }

                this.DeregisterEvents();
            }
        }
 /// <summary>
 /// Session end
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">Event arguments</param>
 public void SessionEnd(object sender, SessionEndEventArgs e)
 {
     this.StopVanguard(e.Context);
 }
Example #26
0
 /// <summary>
 /// On session end
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">Event arguments</param>
 private void SessionEnd(object sender, SessionEndEventArgs e)
 {
     this.implementation.SessionEnd(sender, e);
 }
Example #27
0
 private void SessionEnded_Handler(object sender, SessionEndEventArgs args)
 {
 }
Example #28
0
        /// <summary>
        /// The trigger session end.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void TriggerTestSessionEnd(object sender, SessionEndEventArgs e)
        {
            var testSessionEndArgs = new TestSessionEndArgs();

            this.TriggerInProcDataCollectionMethods(Constants.TestSessionEndMethodName, testSessionEndArgs);
        }
 private void TriggerTestSessionEnd(object sender, SessionEndEventArgs e)
 {
     this.dataCollectionTestCaseEventSender.SendTestSessionEnd(e);
 }
Example #30
0
 private void OnSessionEnd(object?sender, SessionEndEventArgs e)
 {
     _logger?.SetContext(e.Context);
 }