public async Task RespectQueueLimit()
        {
            // Arrange
            var httpClient = new HttpClientMock();

            // Create 10 log events
            var logEvents = Enumerable
                            .Range(1, 10)
                            .Select(number => Some.LogEvent("Event {number}", number))
                            .ToArray();

            using (var sink = new HttpSink(
                       "some/route",
                       1,
                       1,                            // Queue only holds 1 event
                       TimeSpan.FromMilliseconds(1), // 1 ms period
                       new NormalTextFormatter(),
                       new ArrayBatchFormatter(),
                       httpClient))
            {
                // Act
                foreach (var logEvent in logEvents)
                {
                    sink.Emit(logEvent);
                }

                await Task.Delay(TimeSpan.FromMilliseconds(10));    // Sleep 10x the period

                // Assert
                httpClient.LogEvents.Length.ShouldBeLessThan(logEvents.Length);    // Some log events will have been dropped
            }
        }
Пример #2
0
        public async Task NoNetworkTrafficWithoutLogEvents()
        {
            // Arrange
            var httpClient = new Mock <IHttpClient>();

            // ReSharper disable once UnusedVariable
            var httpSink = new HttpSink(
                "api/events",
                1000,
                TimeSpan.FromSeconds(2),
                new NormalRenderedTextFormatter(),
                new DefaultBatchFormatter(),
                httpClient.Object);

            // Act
            await Task.Delay(TimeSpan.FromMinutes(3));

            // Assert
            httpClient.Verify(
                mock => mock.PostAsync(It.IsAny <string>(), It.IsAny <HttpContent>()),
                Times.Never);
        }