internal static void AddNupkgCopiedData(ProtocolDiagnosticNupkgCopiedEvent ncEvent, IReadOnlyDictionary <string, Data> allData)
        {
            if (!allData.TryGetValue(ncEvent.Source, out Data data))
            {
                return;
            }

            lock (data._lock)
            {
                data.NupkgCount++;
                data.NupkgSize += ncEvent.FileSize;
            }
        }
Beispiel #2
0
        public void AddNupkgCopiedData_MultipleEvents_AccumulatesCorrectly()
        {
            // Arrange
            var sizes = new[] { 1, 22, 333, 4444, 55555, 666666 };
            var data  = CreateDataDictionary(SampleSource);

            // Act
            for (int i = 0; i < sizes.Length; i++)
            {
                var nce = new ProtocolDiagnosticNupkgCopiedEvent(SampleSource, sizes[i]);
                PackageSourceTelemetry.AddNupkgCopiedData(nce, data);
            }

            // Assert
            var result = Assert.Single(data).Value;

            Assert.Equal(sizes.Length, result.NupkgCount);
            Assert.Equal(sizes.Sum(), result.NupkgSize);
        }
Beispiel #3
0
        public async Task AddData_IsThreadSafe()
        {
            // Arrange
            var data          = CreateDataDictionary(SampleSource);
            var stringTable   = new ConcurrentDictionary <string, ConcurrentDictionary <string, string> >();
            var eventsToRaise = 10000;
            var sources       = new HashSet <string>
            {
                SampleSource
            };

            Task SendEvents(Action action)
            {
                var tasks = new List <Task>();

                for (int i = 0; i < eventsToRaise; i++)
                {
                    tasks.Add(Task.Run(() => action()));
                }

                return(Task.WhenAll(tasks));
            }

            var resourceEvent    = CreateSampleResourceEvent();
            var httpEvent        = CreateSampleHttpEvent();
            var nupkgCopiedEvent = new ProtocolDiagnosticNupkgCopiedEvent(SampleSource, fileSize: 123456);

            // Act
            var resourceEvents    = Task.Run(() => SendEvents(() => PackageSourceTelemetry.AddResourceData(resourceEvent, data, stringTable)));
            var httpEvents        = Task.Run(() => SendEvents(() => PackageSourceTelemetry.AddHttpData(httpEvent, data)));
            var nupkgCopiedEvents = Task.Run(() => SendEvents(() => PackageSourceTelemetry.AddNupkgCopiedData(nupkgCopiedEvent, data)));
            await Task.WhenAll(resourceEvents, httpEvents, nupkgCopiedEvents);

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

            Assert.Equal(eventsToRaise, pair.Value.Resources.Sum(r => r.Value.count));
            Assert.Equal(eventsToRaise, pair.Value.Http.Requests);
            Assert.Equal(eventsToRaise, pair.Value.NupkgCount);
        }
 private void ProtocolDiagnostics_NupkgCopiedEvent(ProtocolDiagnosticNupkgCopiedEvent ncEvent)
 {
     AddNupkgCopiedData(ncEvent, _data);
 }
Beispiel #5
0
 internal static void RaiseEvent(ProtocolDiagnosticNupkgCopiedEvent ncEvent)
 {
     NupkgCopiedEvent?.Invoke(ncEvent);
 }