Beispiel #1
0
        public void AddAggregateData_DifferentSources()
        {
            // Arrange
            var pde1 = CreateSampleProtocolDiagnosticsEvent(source: "source1");
            var pde2 = CreateSampleProtocolDiagnosticsEvent(source: "source2");
            var data = new ConcurrentDictionary <string, PackageSourceTelemetry.Data>();

            // Act
            PackageSourceTelemetry.AddAggregateData(pde1, data);
            PackageSourceTelemetry.AddAggregateData(pde2, data);

            // Assert
            Assert.Equal(2, data.Count);
        }
Beispiel #2
0
        public void AddAggregateData_HeaderTimingCountedCorrectly()
        {
            // Arrange
            var pde1 = CreateSampleProtocolDiagnosticsEvent(headerDuration: null);
            var pde2 = CreateSampleProtocolDiagnosticsEvent(headerDuration: TimeSpan.FromMilliseconds(100));
            var data = new ConcurrentDictionary <string, PackageSourceTelemetry.Data>();

            // Act
            PackageSourceTelemetry.AddAggregateData(pde1, data);
            PackageSourceTelemetry.AddAggregateData(pde2, data);

            // Assert
            KeyValuePair <string, PackageSourceTelemetry.Data> pair = Assert.Single(data);

            Assert.Equal(1, pair.Value.Nupkg.HeaderTiming.Requests);
            Assert.Equal(2, pair.Value.Nupkg.EventTiming.Requests);
        }
Beispiel #3
0
        public void AddAggregateData_IsThreadSafe()
        {
            // Arrange
            var data          = new ConcurrentDictionary <string, PackageSourceTelemetry.Data>();
            var eventsToRaise = 10000;

            // Act
            Parallel.For(0, eventsToRaise, _ =>
            {
                var pde = CreateSampleProtocolDiagnosticsEvent();
                PackageSourceTelemetry.AddAggregateData(pde, data);
            });

            // Assert
            KeyValuePair <string, PackageSourceTelemetry.Data> pair = Assert.Single(data);

            Assert.Equal(eventsToRaise, pair.Value.Nupkg.EventTiming.Requests);
        }
Beispiel #4
0
        public void AddAggregateData_TimingAggregation()
        {
            // Arrange
            var timings = new[] { TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150), TimeSpan.FromMilliseconds(200) };
            var data    = new ConcurrentDictionary <string, PackageSourceTelemetry.Data>();

            // Act
            for (int i = 0; i < timings.Length; i++)
            {
                var pde = CreateSampleProtocolDiagnosticsEvent(eventDuration: timings[i]);
                PackageSourceTelemetry.AddAggregateData(pde, data);
            }

            // Assert
            var pair  = Assert.Single(data);
            var times = pair.Value.Nupkg.EventTiming;

            Assert.Equal(timings.Length, times.Requests);
            Assert.Equal(timings.Sum(t => t.TotalMilliseconds), times.TotalDuration.TotalMilliseconds, precision: 3);
        }
Beispiel #5
0
        public void AddAggregateData_SplitsMetadataAndNupkgCorrectly(string url, bool isNupkg)
        {
            // Arrange
            var pde  = CreateSampleProtocolDiagnosticsEvent(url: new Uri(url));
            var data = new ConcurrentDictionary <string, PackageSourceTelemetry.Data>();

            // Act
            PackageSourceTelemetry.AddAggregateData(pde, data);

            // Assert
            KeyValuePair <string, PackageSourceTelemetry.Data> pair = Assert.Single(data);

            if (isNupkg)
            {
                Assert.Equal(0, pair.Value.Metadata.EventTiming.Requests);
                Assert.Equal(1, pair.Value.Nupkg.EventTiming.Requests);
            }
            else
            {
                Assert.Equal(1, pair.Value.Metadata.EventTiming.Requests);
                Assert.Equal(0, pair.Value.Nupkg.EventTiming.Requests);
            }
        }