-
Notifications
You must be signed in to change notification settings - Fork 49
Refine test to show minimal metadata needed for errors to be imported successfully #4943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fdd6900
Refine test to show minimal metadata needed for errors to be imported…
andreasohlund b61f8cf
Wording
andreasohlund 3a44196
Better comment
andreasohlund 3f8d5b7
More comments
andreasohlund d786a34
Isolate changes
andreasohlund bd765a0
More rollbacks
andreasohlund 6c9622f
Separate tests for minimal required for ingestion vs minimal required…
andreasohlund 59050c3
Improve assertions
andreasohlund d1a7326
Cleanup
andreasohlund 821f4d9
Consolidate done criteria
andreasohlund 9c8a219
Use header key constants
andreasohlund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...ests/Recoverability/MessageFailures/When_ingesting_failed_message_with_missing_headers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| namespace ServiceControl.AcceptanceTests.Recoverability.MessageFailures; | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using AcceptanceTesting; | ||
| using AcceptanceTesting.EndpointTemplates; | ||
| using Infrastructure; | ||
| using NServiceBus; | ||
| using NServiceBus.AcceptanceTesting; | ||
| using NServiceBus.Routing; | ||
| using NServiceBus.Transport; | ||
| using NUnit.Framework; | ||
| using ServiceControl.MessageFailures.Api; | ||
|
|
||
| class When_ingesting_failed_message_with_missing_headers : AcceptanceTest | ||
| { | ||
| [Test] | ||
| public async Task Should_be_ingested_when_minimal_required_headers_is_present() | ||
| { | ||
| var testStartTime = DateTime.UtcNow; | ||
|
|
||
| var context = await Define<TestContext>(c => c.AddMinimalRequiredHeaders()) | ||
| .WithEndpoint<FailingEndpoint>() | ||
| .Done(async c => await TryGetFailureFromApi(c)) | ||
| .Run(); | ||
|
|
||
| var failure = context.Failure; | ||
|
|
||
| Assert.That(failure, Is.Not.Null); | ||
| Assert.That(failure.TimeSent, Is.Null); | ||
|
|
||
| //No failure time will result in utc now being used | ||
| Assert.That(failure.TimeOfFailure, Is.GreaterThan(testStartTime)); | ||
|
|
||
| // Both host and endpoint name is currently needed so this will be null since no host can be detected from the failed q header | ||
| Assert.That(failure.ReceivingEndpoint, Is.Null); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_include_headers_required_by_ServicePulse() | ||
| { | ||
| var context = await Define<TestContext>(c => | ||
| { | ||
| c.AddMinimalRequiredHeaders(); | ||
|
|
||
| // This is needed for ServiceControl to be able to detect both endpoint (via failed q header) and host via the processing machine header | ||
| // Missing endpoint or host will cause a null ref in ServicePulse | ||
| c.Headers[Headers.ProcessingMachine] = "MyMachine"; | ||
|
|
||
| c.Headers["NServiceBus.ExceptionInfo.ExceptionType"] = "SomeExceptionType"; | ||
| c.Headers["NServiceBus.ExceptionInfo.Message"] = "Some message"; | ||
| }) | ||
| .WithEndpoint<FailingEndpoint>() | ||
| .Done(async c => await TryGetFailureFromApi(c)) | ||
| .Run(); | ||
|
|
||
| var failure = context.Failure; | ||
|
|
||
| Assert.That(failure, Is.Not.Null); | ||
|
|
||
| // ServicePulse assumes that the receiving endpoint name is present | ||
| Assert.That(failure.ReceivingEndpoint, Is.Not.Null); | ||
| Assert.That(failure.ReceivingEndpoint.Name, Is.EqualTo(context.EndpointNameOfReceivingEndpoint)); | ||
| Assert.That(failure.ReceivingEndpoint.Host, Is.EqualTo("MyMachine")); | ||
|
|
||
| // ServicePulse needs both an exception type and description to render the UI in a resonable way | ||
| Assert.That(failure.Exception.ExceptionType, Is.EqualTo("SomeExceptionType")); | ||
| Assert.That(failure.Exception.Message, Is.EqualTo("Some message")); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task TimeSent_should_not_be_casted() | ||
| { | ||
| var sentTime = DateTime.Parse("2014-11-11T02:26:58.000462Z"); | ||
|
|
||
| var context = await Define<TestContext>(c => | ||
| { | ||
| c.AddMinimalRequiredHeaders(); | ||
| c.Headers.Add("NServiceBus.TimeSent", DateTimeOffsetHelper.ToWireFormattedString(sentTime)); | ||
|
andreasohlund marked this conversation as resolved.
Outdated
|
||
| }) | ||
| .WithEndpoint<FailingEndpoint>() | ||
| .Done(async c => await TryGetFailureFromApi(c)) | ||
| .Run(); | ||
|
|
||
| var failure = context.Failure; | ||
|
|
||
| Assert.That(failure, Is.Not.Null); | ||
| Assert.That(failure.TimeSent, Is.EqualTo(sentTime)); | ||
| } | ||
|
|
||
| async Task<bool> TryGetFailureFromApi(TestContext context) | ||
| { | ||
| context.Failure = await this.TryGet<FailedMessageView>($"/api/errors/last/{context.UniqueMessageId}"); | ||
| return context.Failure != null; | ||
| } | ||
|
|
||
| class TestContext : ScenarioContext | ||
| { | ||
| public string MessageId { get; } = Guid.NewGuid().ToString(); | ||
|
|
||
| public string EndpointNameOfReceivingEndpoint => "MyEndpoint"; | ||
|
|
||
| public string UniqueMessageId => DeterministicGuid.MakeId(MessageId, EndpointNameOfReceivingEndpoint).ToString(); | ||
|
|
||
| public Dictionary<string, string> Headers { get; } = []; | ||
|
|
||
| public FailedMessageView Failure { get; set; } | ||
|
|
||
| public void AddMinimalRequiredHeaders() | ||
| { | ||
| Headers["NServiceBus.FailedQ"] = EndpointNameOfReceivingEndpoint; | ||
|
andreasohlund marked this conversation as resolved.
Outdated
|
||
| Headers[NServiceBus.Headers.MessageId] = MessageId; | ||
| } | ||
| } | ||
|
|
||
| class FailingEndpoint : EndpointConfigurationBuilder | ||
| { | ||
| public FailingEndpoint() => EndpointSetup<DefaultServerWithoutAudit>(); | ||
|
|
||
| class SendFailedMessage : DispatchRawMessages<TestContext> | ||
| { | ||
| protected override TransportOperations CreateMessage(TestContext context) | ||
| { | ||
| var outgoingMessage = new OutgoingMessage(context.MessageId, context.Headers, Array.Empty<byte>()); | ||
|
|
||
| return new TransportOperations(new TransportOperation(outgoingMessage, new UnicastAddressTag("error"))); | ||
| } | ||
| } | ||
| } | ||
| } | ||
126 changes: 0 additions & 126 deletions
126
...ts/Recoverability/MessageFailures/When_processing_message_with_missing_metadata_failed.cs
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.