public void verify_retry_start_execution_tracking() { AnotherSampleCommandHandler.numOfFailure = 2; AnotherSampleCommandHandler.exceptionToThrow = new ConflictingCommandException("TEST_1", null); AnotherSampleCommandHandler.setEventOnThrow = false; var sampleMessage = new AnotherSampleTestCommand(10); _bus.Send(sampleMessage); var handled = _handler.Reset.WaitOne(10000); //cycle until we found handled message on tracking TrackedMessageModel track = null; DateTime startTime = DateTime.Now; do { Thread.Sleep(50); var tracks = _messages.FindAll().ToList(); Assert.That(tracks, Has.Count.EqualTo(1)); track = tracks.Single(); } while ( track.ExecutionCount < AnotherSampleCommandHandler.numOfFailure && DateTime.Now.Subtract(startTime).TotalSeconds < 4 ); Assert.That(track.MessageId, Is.EqualTo(sampleMessage.MessageId.ToString())); Assert.That(track.Description, Is.EqualTo(sampleMessage.Describe())); Assert.That(track.StartedAt, Is.Not.Null); Assert.That(track.CompletedAt, Is.Not.Null); Assert.That(track.FailedAt, Is.Null); Assert.That(track.DispatchedAt, Is.Null); Assert.That(track.LastExecutionStartTime, Is.Not.Null); Assert.That(track.ExecutionCount, Is.EqualTo(3)); Assert.That(track.ExecutionStartTimeList.Length, Is.EqualTo(3)); }
public async Task Verify_retry_start_execution_tracking(Boolean wrapInAggregateException) { var tracks = _messages.FindAll().ToList(); Assert.That(tracks, Has.Count.EqualTo(0), "messages collection is not empty"); var sampleMessage = new AnotherSampleTestCommand(2, "verify_retry_start_execution_tracking"); AnotherSampleCommandHandler.SetFixtureData( sampleMessage.MessageId, 2, new ConcurrencyException("TEST_1", null), true, wrapInAggregateException: wrapInAggregateException); await _bus.Send(sampleMessage).ConfigureAwait(false); //cycle until we found handled message on tracking TrackedMessageModel track; DateTime startTime = DateTime.Now; { Thread.Sleep(200); track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString() && t.Completed == true); } while ( track == null && DateTime.Now.Subtract(startTime).TotalSeconds < 5 ) { ; } if (track == null) { //failure, try to recover the message id to verify what was wrong track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString()); } Assert.That(track.MessageId, Is.EqualTo(sampleMessage.MessageId.ToString())); Assert.That(track.Description, Is.EqualTo(sampleMessage.Describe())); Assert.That(track.StartedAt, Is.Not.Null); Assert.That(track.CompletedAt, Is.Not.Null); Assert.That(track.DispatchedAt, Is.Null); Assert.That(track.Completed, Is.True); Assert.That(track.Success, Is.True); Assert.That(track.LastExecutionStartTime, Is.Not.Null); Assert.That(track.ExecutionCount, Is.EqualTo(3)); Assert.That(track.ExecutionStartTimeList.Length, Is.EqualTo(3)); }
public async Task Verify_exceeding_retry(Boolean wrapInAggregateException) { var sampleMessage = new AnotherSampleTestCommand(3, "verify_exceeding_retry"); AnotherSampleCommandHandler.SetFixtureData( sampleMessage.MessageId, Int32.MaxValue, new ConcurrencyException("TEST_1", null), false, wrapInAggregateException: wrapInAggregateException); await _bus.Send(sampleMessage).ConfigureAwait(false); //cycle until we found handled message on tracking TrackedMessageModel track; DateTime startTime = DateTime.Now; do { Thread.Sleep(200); track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString() && t.ExecutionCount == 10 && t.Completed == true); }while ( track == null && DateTime.Now.Subtract(startTime).TotalSeconds < 4 ); if (track == null) { //failure, try to recover the message id to verify what was wrong track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString()); } if (track == null) { throw new AssertionException($"Message {sampleMessage.MessageId} did not generate tracking info"); } Assert.That(track.MessageId, Is.EqualTo(sampleMessage.MessageId.ToString())); Assert.That(track.Description, Is.EqualTo(sampleMessage.Describe())); Assert.That(track.StartedAt, Is.Not.Null); Assert.That(track.CompletedAt, Is.Not.Null); Assert.That(track.Completed, Is.True); Assert.That(track.Success, Is.False); Assert.That(track.ExecutionCount, Is.EqualTo(10), "Execution retry for conflict should do for 10 times"); }
public async Task Verify_failure_tracking_for_domain_exception(Boolean wrapInAggregateException) { //We decide to fail only one time var sampleMessage = new AnotherSampleTestCommand(1, "verify_failure_tracking_for_domain_exception"); AnotherSampleCommandHandler.SetFixtureData( sampleMessage.MessageId, 10, new DomainException("TEST_1", "Test Exception for verify_failure_tracking_for_domain_exception test", null), true, wrapInAggregateException: wrapInAggregateException); await _bus.Send(sampleMessage).ConfigureAwait(false); //cycle until we found handled message on tracking with specified condition TrackedMessageModel track; DateTime startTime = DateTime.Now; do { Thread.Sleep(200); track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString() && t.ExecutionCount == 1 && t.Completed == true && t.Success == false); }while ( track == null && DateTime.Now.Subtract(startTime).TotalSeconds < 4 ); if (track == null) { //failure, try to recover the message id to verify what was wrong track = _messages.AsQueryable().SingleOrDefault(t => t.MessageId == sampleMessage.MessageId.ToString()); } //donormal assertion if (track == null) { throw new AssertionException($"Message {sampleMessage.MessageId} did not generate tracking info"); } var allTracking = _messages.FindAll().ToList(); if (allTracking.Count != 1) { Console.WriteLine($"Too many tracking elements: {allTracking.Count}"); foreach (var t in allTracking) { Console.WriteLine(t.ToBsonDocument()); } } Assert.That(track.MessageId, Is.EqualTo(sampleMessage.MessageId.ToString())); Assert.That(track.Description, Is.EqualTo(sampleMessage.Describe())); Assert.That(track.StartedAt, Is.Not.Null); Assert.That(track.CompletedAt, Is.Not.Null); Assert.That(track.DispatchedAt, Is.Null); Assert.That(track.ErrorMessage, Is.Not.Empty); Assert.That(track.Completed, Is.True); Assert.That(track.Success, Is.False); Assert.That(track.ExecutionCount, Is.EqualTo(1)); }