public void Log4NetConfigurationIsCorrect() { IHealthCheckResult result = GetHealthCheckResult(Log4NetConfigurationKeys.Correct); Assert.IsTrue(result.Passed); StringAssert.Contains(result.Message, "The log4net configuration is correct."); }
public void DateParameterMissing() { IHealthCheckResult result = GetHealthCheckResult(Log4NetConfigurationKeys.DateParameterMissing); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The definition of the @Date parameter is missing."); }
public void ExceptionThrownInHealthCheckImplementationIsReportedAsFailedHealthCheckResult() { IHealthCheck firstHealthCheck = m_Repository.StrictMock <IHealthCheck>(); HealthCheckException healthCheckException = m_Repository.StrictMock <HealthCheckException>(); using (m_Repository.Record()) { Expect.Call(firstHealthCheck.Execute()).Throw(healthCheckException); Expect.Call(healthCheckException.Message).Return("Sample Exception"); m_Repository.ReplayAll(); HealthCheckResultCollection resultCollection = HealthCheckRunner.RunHealthChecks(new HealthChecklistCollection(new[] { firstHealthCheck })); Assert.AreEqual(1, resultCollection.Count); IHealthCheckResult result = resultCollection[0]; Assert.IsFalse(result.Passed); StringAssert.StartsWith(result.Message, "An exception was thrown during the execution of the Health Check"); StringAssert.Contains(result.Message, "Sample Exception"); m_Repository.VerifyAll(); } }
public async ValueTask <IHealthCheckResult> CheckAsync(CancellationToken cancellationToken) { while (_cacheExpiration <= UtcNow) { // Can't use a standard lock here because of async, so we'll use this flag to determine when we should write a value, // and the waiters who aren't allowed to write will just spin wait for the new value. if (Interlocked.Exchange(ref _writerCount, 1) != 0) { await Task.Delay(5, cancellationToken).ConfigureAwait(false); continue; } try { _cachedResult = await Check(cancellationToken).ConfigureAwait(false); _cacheExpiration = UtcNow + CacheDuration; break; } finally { _writerCount = 0; } } return(_cachedResult); }
public void NoResultsReturnedFromSproc() { IHealthCheck healthCheck = GetHealthCheck(null, false); IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The IsHealthy_ObjectExistenceCheck sproc produced no result row."); }
public void CategoryNotDefined() { IHealthCheckResult result = BuildHealthCheckAndSetExpectations(false, BuildAllTrueArray()); m_MockRepository.VerifyAll(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The performance counter category has not been registered."); }
public void ServiceIsNotRunning() { IHealthCheckResult result = RunHealthCheck(false); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The Feature Store service is not running."); m_MockRepository.VerifyAll(); }
public void OnGet() { var timedTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3)); var stopwatch = Stopwatch.StartNew(); var checkResult = healthCheck.CheckAsync(timedTokenSource.Token).GetAwaiter().GetResult(); ExecutionTime = stopwatch.Elapsed; HealthCheckResult = checkResult; }
public void CategoryDefinedMissingTwoCounters() { IHealthCheckResult result = BuildHealthCheckAndSetExpectations(true, BuildAlternatingBoolArray()); m_MockRepository.VerifyAll(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "category has been registered, but counter(s) are missing"); StringAssert.Contains(result.Message, m_PerformanceCounterDefinitions[1].CounterName); }
public void PerformanceCountersDefinedHealthCheck() { IHealthCheckResult result = BuildHealthCheckAndSetExpectations(true, BuildAllTrueArray()); m_MockRepository.VerifyAll(); Assert.IsTrue(result.Passed); StringAssert.Contains(result.Message, "The performance counter category and all counters have been registered."); }
public void UserIsNotFoundInRole() { IHealthCheck healthCheck = BuildHealthCheckAndSetExpectations(false, true); IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "not found in the necessary role."); m_MockRepository.VerifyAll(); }
public void NoRowsReturnedFromRoleMemberQuery() { IHealthCheck healthCheck = BuildHealthCheckAndSetExpectations(true, false); IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The call to check if the user was in the necessary role returned no row."); m_MockRepository.VerifyAll(); }
public void Add(string name, IHealthCheckResult checkResult) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (checkResult == null) { throw new ArgumentNullException(nameof(checkResult)); } _results.Add(name, checkResult); }
public void ServiceIsNotInstalled() { IServiceStateInquisitor serviceStateInquisitor = m_MockRepository.StrictMock <IServiceStateInquisitor>(); IHealthCheck healthCheck = FeatureStoreServiceStateHealthCheck.Create(serviceStateInquisitor); using (m_MockRepository.Record()) { Expect.Call(serviceStateInquisitor.ServiceIsRunning()).Throw(new ServiceNotInstalledException()); m_MockRepository.ReplayAll(); } IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "The Feature Store service is not installed."); }
public void SqlServerStorageContainerConnectivityHealthCheckPasses() { DbConnection connection = m_MockRepository.StrictMock <DbConnection>(); IHealthCheck healthCheck = SqlServerStorageContainerConnectivityHealthCheck.Create(connection); using (m_MockRepository.Record()) { Expect.Call(connection.Open); Expect.Call(connection.ConnectionString).Return("SampleConnectionString"); m_MockRepository.ReplayAll(); IHealthCheckResult result = healthCheck.Execute(); Assert.IsTrue(result.Passed); StringAssert.Contains(result.Message, "Connection to SqlServer database succeeded"); StringAssert.Contains(result.Message, "SampleConnectionString"); m_MockRepository.VerifyAll(); } }
public void HealthCheckRunnerExecutesListOfHealthChecksAndAllSucceed() { IHealthCheck firstHealthCheck = m_Repository.StrictMock <IHealthCheck>(); IHealthCheck secondHealthCheck = m_Repository.StrictMock <IHealthCheck>(); IHealthCheck thirdHealthCheck = m_Repository.StrictMock <IHealthCheck>(); IHealthCheckResult firstHealthCheckResult = m_Repository.StrictMock <IHealthCheckResult>(); IHealthCheckResult secondHealthCheckResult = m_Repository.StrictMock <IHealthCheckResult>(); IHealthCheckResult thirdHealthCheckResult = m_Repository.StrictMock <IHealthCheckResult>(); using (m_Repository.Record()) { Expect.Call(firstHealthCheck.Execute()).Return(firstHealthCheckResult); Expect.Call(secondHealthCheck.Execute()).Return(secondHealthCheckResult); Expect.Call(thirdHealthCheck.Execute()).Return(thirdHealthCheckResult); Expect.Call(firstHealthCheckResult.Passed).Return(true); Expect.Call(firstHealthCheckResult.Message).Return("The Health Check was successful."); Expect.Call(secondHealthCheckResult.Passed).Return(true); Expect.Call(secondHealthCheckResult.Message).Return("The Health Check was successful."); Expect.Call(thirdHealthCheckResult.Passed).Return(true); Expect.Call(thirdHealthCheckResult.Message).Return("The Health Check was successful."); m_Repository.ReplayAll(); HealthCheckResultCollection resultCollection = HealthCheckRunner.RunHealthChecks( new HealthChecklistCollection(new[] { firstHealthCheck, secondHealthCheck, thirdHealthCheck })); Assert.AreEqual(3, resultCollection.Count); foreach (IHealthCheckResult healthCheckResult in resultCollection) { Assert.IsTrue(healthCheckResult.Passed); StringAssert.Contains(healthCheckResult.Message, "success"); } m_Repository.VerifyAll(); } }
public async ValueTask <IHealthCheckResult> CheckAsync( CancellationToken cancellationToken = default(CancellationToken)) { IHealthCheckResult result = null; if (_store == null) { result = HealthCheckResult.Unhealthy("IHealthCheckStore is null, DI did not work"); } var health = await _store.IsHealthyAsync(); if (health.Health == false) { var unhealthyKeys = string.Join(".", health.UnHealthyKeys); result = HealthCheckResult.Unhealthy($"the following aggregate keys are unhealthy:[{unhealthyKeys}]"); } else { result = HealthCheckResult.Healthy("Everything in Aggregate is healthy"); } return(result); }
public void OneObjectDoesNotExist() { var results = new[] { new Tuple <bool, string>(true, "Role1Exists"), new Tuple <bool, string>(true, "Role2Exists"), new Tuple <bool, string>(false, "Table1Exists"), new Tuple <bool, string>(true, "Table2Exists"), new Tuple <bool, string>(true, "Table3Exists"), new Tuple <bool, string>(true, "Sproc1Exists"), new Tuple <bool, string>(true, "Sproc2Exists") }; IHealthCheck healthCheck = GetHealthCheck(results, true); IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "Failed to find 'Table1Exists' object in database."); m_MockRepository.VerifyAll(); }
public void AllObjectsExist() { var results = new[] { new Tuple <bool, string>(true, "Role1Exists"), new Tuple <bool, string>(true, "Role2Exists"), new Tuple <bool, string>(true, "Table1Exists"), new Tuple <bool, string>(true, "Table2Exists"), new Tuple <bool, string>(true, "Table3Exists"), new Tuple <bool, string>(true, "Sproc1Exists"), new Tuple <bool, string>(true, "Sproc2Exists") }; IHealthCheck healthCheck = GetHealthCheck(results, true); IHealthCheckResult result = healthCheck.Execute(); Assert.IsTrue(result.Passed); Console.WriteLine(result.Message); m_MockRepository.VerifyAll(); }
private void AssertExceptionHandled <T>(string exceptionMessage) where T : Exception { DbConnection connection = m_MockRepository.StrictMock <DbConnection>(); IHealthCheck healthCheck = SqlServerStorageContainerConnectivityHealthCheck.Create(connection); T exception = m_MockRepository.StrictMock <T>(); using (m_MockRepository.Record()) { Expect.Call(connection.Open).Throw(exception); Expect.Call(connection.ConnectionString).Return("SampleConnectionString"); Expect.Call(exception.Message).Return(exceptionMessage); m_MockRepository.ReplayAll(); } IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "An exception occured opening the connection to the database:"); StringAssert.Contains(result.Message, exceptionMessage); m_MockRepository.VerifyAll(); }
public void InvalidOperationExceptionIsHandledCorrectly() { const string exceptionMessage = "An invalid operation was attempted."; DbConnection connection = m_MockRepository.StrictMock <DbConnection>(); IHealthCheck healthCheck = SqlServerStorageContainerObjectExistenceHealthCheck.Create(connection); InvalidOperationException exception = m_MockRepository.StrictMock <InvalidOperationException>(); using (m_MockRepository.Record()) { Expect.Call(connection.CreateCommand()).Throw(exception); Expect.Call(exception.Message).Return(exceptionMessage); Expect.Call(connection.ConnectionString).Return("SampleConnectionString"); m_MockRepository.ReplayAll(); } IHealthCheckResult result = healthCheck.Execute(); Assert.IsFalse(result.Passed); StringAssert.Contains(result.Message, "An exception occured opening the connection to the database:"); StringAssert.Contains(result.Message, exceptionMessage); m_MockRepository.VerifyAll(); }
public void AddResult(string name, IHealthCheckResult result) { _results.Add(name, result); }
public void Add(IHealthCheckResult checkResult) { _results[checkResult.GetType().Name] = checkResult ?? throw new ArgumentNullException(nameof(checkResult)); }
public NamedCheckResult(string name, IHealthCheckResult result) { Name = name; Result = result; }
private static string ToDescriptiveString(IHealthCheckResult result) => $"{result.CheckStatus} ({result.Description})";