public void HeartbeatShouldLogSuccess() { var formatter = new CommsLogEventFormatter(); var logger = new GraphLogger(nameof(this.HeartbeatShouldLogSuccess)); logger.DiagnosticLevel = TraceLevel.Verbose; var loggerCount = 0; var observer = new Observer <LogEvent>( logger, onNext: @event => { Interlocked.Increment(ref loggerCount); this.TestContext.WriteLine(formatter.Format(@event)); }, onError: @exception => { Assert.Fail(@exception.ToString()); }); var handler = new TestHandler(TimeSpan.FromSeconds(1), logger, args => { return(Task.CompletedTask); }); Thread.Sleep(TimeSpan.FromSeconds(4)); Assert.IsTrue(loggerCount >= 4, $"loggerCount >= 4 failed: loggerCount = {loggerCount}"); handler.Dispose(); }
public void HeartbeatShouldLogFailure() { var formatter = new CommsLogEventFormatter(); var logger = new GraphLogger(nameof(this.HeartbeatShouldLogSuccess)); logger.DiagnosticLevel = TraceLevel.Error; var errorCount = 0; var observer = new Observer <LogEvent>( logger, onNext: @event => { Interlocked.Increment(ref errorCount); this.TestContext.WriteLine(formatter.Format(@event)); }, onError: @exception => { Assert.Fail(@exception.ToString()); }); var handler = new TestHandler(TimeSpan.FromSeconds(1), logger, args => { throw new Exception("Something went wrong!!!"); }); Thread.Sleep(TimeSpan.FromSeconds(4)); Assert.IsTrue(errorCount >= 2, $"errorCount >= 2 failed: errorCount = {errorCount}"); handler.Dispose(); }
public void HeartbeatShouldTrigger() { var logger = new GraphLogger(nameof(this.HeartbeatShouldTrigger)); var handlerCount = 0; var handler = new TestHandler(TimeSpan.FromSeconds(1), logger, args => { Interlocked.Increment(ref handlerCount); return(Task.CompletedTask); }); Thread.Sleep(TimeSpan.FromSeconds(3)); Assert.IsTrue(handlerCount >= 2, $"handlerCount >= 2 failed: handlerCount = {handlerCount}"); handler.Dispose(); handlerCount = 0; Thread.Sleep(TimeSpan.FromSeconds(1)); Assert.AreEqual(0, handlerCount); handler.Dispose(); }