예제 #1
0
 public void TestServiceManagerCommon(ServiceManagerServices service)
 {
     TestBoolKey($"ServiceManager:{service.ToString()}Service:Enabled");
     TestIntKey($"ServiceManager:{service.ToString()}Service:Interval");
 }
예제 #2
0
        public async Task RunsOnlyIfEnabled(ServiceManagerServices service)
        {
            // Arrange
            EnableServices(service);

            var serviceManagerService = new ServiceManagerService(
                _mockLog.Object,
                _mockServiceProvider.Object,
                _config.Object
                );

            // Act
            var task = serviceManagerService.StartServices();
            await Task.Delay(3000);

            serviceManagerService.StopServices();

            // Let it finish its job
            // Check that services are stopped
            // If not done in 30 seconds, consider timeout
            Assert.Equal(await Task.WhenAny(task, Task.Delay(new TimeSpan(0, 0, 30))), task);

            // Assert

            // Cache
            _mockCacheService.Verify(
                cache => cache.CacheMetricAsync(It.IsAny <Metric>()),
                service == ServiceManagerServices.Cache ? Times.AtLeastOnce() : Times.Never()
                );

            // Clean
            _mockCleanService.Verify(
                clean => clean.CleanDataPointsAsync(It.IsAny <TimeSpan?>()),
                service == ServiceManagerServices.Clean ? Times.AtLeastOnce() : Times.Never()
                );

            // Demo
            _mockDemoService.Verify(
                demo => demo.GenerateDemoDataAsync(
                    It.IsAny <Metrics>(),
                    It.IsAny <string>(),
                    It.IsAny <DateTime?>()
                    ),
                service == ServiceManagerServices.Demo ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDemoService.Verify(
                demo => demo.GenerateDemoLogAsync(It.IsAny <string>()),
                service == ServiceManagerServices.Demo ? Times.AtLeastOnce() : Times.Never()
                );

            // Health
            _mockHealthService.Verify(
                health => health.ProduceHealthReportAsync(),
                service == ServiceManagerServices.Health ? Times.AtLeastOnce() : Times.Never()
                );

            // Discrepancy
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindGapsAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindPingFailuresAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindHighLoadsAsync(
                    It.IsAny <Metric>(),
                    It.IsAny <TimeSpan>()
                    ),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.RecordDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.FindResolvedDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );
            _mockDiscrepancyService.Verify(
                discrepancy => discrepancy.ResolveDiscrepanciesAsync(It.IsAny <IEnumerable <Discrepancy> >()),
                service == ServiceManagerServices.Discrepancy ? Times.AtLeastOnce() : Times.Never()
                );


            // Notification
            _mockNotificationService.Verify(
                notif => notif.ProcessNotificationQueueAsync(),
                service == ServiceManagerServices.Notification ? Times.AtLeastOnce() : Times.Never()
                );

            // Ping
            _mockPingService.Verify(
                ping => ping.PingServerAsync(It.IsAny <PingSetting>()),
                service == ServiceManagerServices.Ping ? Times.AtLeastOnce() : Times.Never()
                );

            // Verify run until completion
            _mockLog
            .Verify(
                log => log.Log(
                    LogLevel.Information,
                    It.IsAny <EventId>(),
                    It.Is <FormattedLogValues>(
                        v => v
                        .ToString()
                        .Contains(
                            $"{service.ToString()} service run complete",
                            StringComparison.OrdinalIgnoreCase
                            )
                        ),
                    It.IsAny <Exception>(),
                    It.IsAny <Func <object, Exception, string> >()
                    )
                );
        }