Example #1
0
        public void ShouldSendSyncEventWhenInsideAsyncWithSyncEventSpecified()
        {
            const string name       = "ToString";
            const long   durationUs = 1000000;
            Type         type       = typeof(int);
            var          logger     = Substitute.For <ILogger>();

            bool InsideAsync() => true;

            var classUnderTest = new ChromeTracingLogger(_processId, logger, InsideAsync);

            classUnderTest.TraceEvent(name, EventType.Sync, type, durationUs, _timestamp,
                                      _threadId);

            Func <ChromeTracingLogger.Event, bool> verifyFormat = (traceEvent) =>
                                                                  traceEvent.Name.Contains(name) && traceEvent.Name.Contains(type.FullName) &&
                                                                  durationUs == traceEvent.DurationUs && _timestamp.Equals(traceEvent.TimestampUs) &&
                                                                  _threadIdAsyncEvent == traceEvent.ThreadId && _processId == traceEvent.ProcessId &&
                                                                  traceEvent.Category.Contains(_expectedCategorySync);

            logger.Received(1).Trace(Arg.Is <string>(message => verifyFormat(
                                                         Newtonsoft.Json.JsonConvert
                                                         .DeserializeObject <
                                                             ChromeTracingLogger.Event>(
                                                             message))));
        }
        public virtual ChromeTracingLogger GetChromeTracingLogger()
        {
            if (_chromeTracingLogger == null)
            {
                int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
                var logger    = YetiLog.GetTraceLogger(YetiLog.ToLogFileDateTime(DateTime.Now));
                _chromeTracingLogger = new ChromeTracingLogger(
                    processId, logger, GetTaskExecutor().IsInsideAsyncContext);
            }

            return(_chromeTracingLogger);
        }
        public void SetUp()
        {
            _processId   = 0;
            _insideAsync = () => true;

            _logger = Substitute.For <ILogger>();
            _chromeTracingLogger = new ChromeTracingLogger(_processId, _logger, _insideAsync);
            _timeSource          = new MonotonicTimeSource();

            _verifyNotMetadataEvent = (eventTraced) =>
            {
                var deserializedTrace =
                    JsonConvert.DeserializeObject <ChromeTracingLogger.Event>(eventTraced);
                return(deserializedTrace.Phase != 'M');
            };
        }
Example #4
0
        public void ShouldSendSyncEventToNLogLoggerInJsonFormatWhenNotInsideAsyncScope()
        {
            const string traceName  = "ToString";
            const long   durationUs = 1000000;
            Type         type       = typeof(int);
            var          logger     = Substitute.For <ILogger>();

            var classUnderTest = new ChromeTracingLogger(_processId, logger, _notInsideAsync);

            classUnderTest.TraceEvent(traceName, EventType.Sync, type, durationUs, _timestamp,
                                      _threadId);

            Func <ChromeTracingLogger.Event, bool> verifyFormat = (traceEvent) =>
                                                                  traceEvent.Name.Contains(traceName) && traceEvent.Name.Contains(type.FullName) &&
                                                                  durationUs == traceEvent.DurationUs && _timestamp.Equals(traceEvent.TimestampUs) &&
                                                                  _threadId == traceEvent.ThreadId && _processId == traceEvent.ProcessId;

            // TODO: Test NLog ILogger state without using NSubstitute
            logger.Received(1).Trace(Arg.Is <string>(message => verifyFormat(
                                                         Newtonsoft.Json.JsonConvert
                                                         .DeserializeObject <
                                                             ChromeTracingLogger.Event>(
                                                             message))));
        }