-
Notifications
You must be signed in to change notification settings - Fork 48
Remove header instead #4839
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
Remove header instead #4839
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
22 changes: 22 additions & 0 deletions
22
src/ServiceControl.MultiInstance.AcceptanceTests/Recoverability/WhenRetrying.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,22 @@ | ||
| namespace ServiceControl.MultiInstance.AcceptanceTests.Recoverability; | ||
|
|
||
| using System.Threading.Tasks; | ||
| using AcceptanceTesting; | ||
| using MessageFailures; | ||
| using MessageFailures.Api; | ||
| using TestSupport; | ||
|
|
||
| abstract class WhenRetrying : AcceptanceTest | ||
| { | ||
| protected Task<SingleResult<FailedMessage>> GetFailedMessage(string uniqueMessageId, string instance, FailedMessageStatus expectedStatus) | ||
| { | ||
| if (uniqueMessageId == null) | ||
| { | ||
| return Task.FromResult(SingleResult<FailedMessage>.Empty); | ||
| } | ||
|
|
||
| return this.TryGet<FailedMessage>($"/api/errors/{uniqueMessageId}", f => f.Status == expectedStatus, instance); | ||
| } | ||
|
|
||
| protected Task<ManyResult<FailedMessageView>> GetAllFailedMessage(string instance, FailedMessageStatus expectedStatus) => this.TryGetMany<FailedMessageView>("/api/errors", f => f.Status == expectedStatus, instance); | ||
| } |
127 changes: 127 additions & 0 deletions
127
...trol.MultiInstance.AcceptanceTests/Recoverability/WhenRetryingSameMessageMultipleTimes.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,127 @@ | ||
| namespace ServiceControl.MultiInstance.AcceptanceTests.Recoverability | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using AcceptanceTesting; | ||
| using AcceptanceTesting.EndpointTemplates; | ||
| using MessageFailures; | ||
| using NServiceBus; | ||
| using NServiceBus.AcceptanceTesting; | ||
| using NServiceBus.Settings; | ||
| using NUnit.Framework; | ||
| using ServiceControl.Infrastructure; | ||
| using TestSupport; | ||
|
|
||
| class WhenRetryingSameMessageMultipleTimes : WhenRetrying | ||
| { | ||
| public enum RetryType | ||
| { | ||
| NoEdit, | ||
| Edit | ||
| } | ||
|
|
||
| [TestCase(new[] { RetryType.NoEdit, RetryType.NoEdit, RetryType.Edit })] | ||
| [TestCase(new[] { RetryType.Edit, RetryType.NoEdit, RetryType.Edit })] | ||
| [TestCase(new[] { RetryType.NoEdit, RetryType.Edit, RetryType.NoEdit })] | ||
| [TestCase(new[] { RetryType.Edit, RetryType.Edit, RetryType.NoEdit })] | ||
| public async Task WithMixOfRetryTypes(RetryType[] retryTypes) | ||
| { | ||
| CustomServiceControlPrimarySettings = s => { s.AllowMessageEditing = true; }; | ||
|
|
||
| await Define<MyContext>() | ||
| .WithEndpoint<FailureEndpoint>(b => | ||
| b.When(bus => bus.SendLocal(new MyMessage())).DoNotFailOnErrorMessages()) | ||
| .Done(async c => | ||
| { | ||
| if (c.RetryCount >= retryTypes.Length) // Are all retries done? | ||
| { | ||
| return !(await GetAllFailedMessage(ServiceControlInstanceName, FailedMessageStatus.Unresolved)) | ||
| .HasResult; // Should return true if all failed messages are no longer unresolved | ||
| } | ||
|
|
||
| if (retryTypes[c.RetryCount] == RetryType.Edit) | ||
| { | ||
| var results = await GetAllFailedMessage(ServiceControlInstanceName, | ||
| FailedMessageStatus.Unresolved); | ||
| if (!results.HasResult) | ||
| { | ||
| return false; // No failed messages yet | ||
| } | ||
|
|
||
| var result = results.Items.Single(); | ||
|
|
||
| c.MessageId = result.MessageId; | ||
| } | ||
|
|
||
| var failedMessage = await GetFailedMessage(c.UniqueMessageId, ServiceControlInstanceName, FailedMessageStatus.Unresolved); | ||
| if (!failedMessage.HasResult) | ||
| { | ||
| return false; // No failed message yet | ||
| } | ||
|
|
||
| if (retryTypes[c.RetryCount] == RetryType.Edit) | ||
| { | ||
| await this.Post<object>($"/api/edit/{failedMessage.Item.UniqueMessageId}", | ||
| new | ||
| { | ||
| MessageBody = $"{{ \"Name\": \"Hello {c.RetryCount}\" }}", | ||
| MessageHeaders = failedMessage.Item.ProcessingAttempts[^1].Headers | ||
| }, null, | ||
| ServiceControlInstanceName); | ||
| } | ||
| else | ||
| { | ||
| await this.Post<object>($"/api/errors/{failedMessage.Item.UniqueMessageId}/retry", null, null, | ||
| ServiceControlInstanceName); | ||
| } | ||
|
|
||
| c.RetryCount++; | ||
|
|
||
| return false; | ||
|
|
||
| }) | ||
| .Run(TimeSpan.FromMinutes(2)); | ||
| } | ||
|
|
||
| class FailureEndpoint : EndpointConfigurationBuilder | ||
| { | ||
| public FailureEndpoint() => EndpointSetup<DefaultServerWithoutAudit>(c => { c.NoRetries(); }); | ||
|
|
||
| public class MyMessageHandler(MyContext testContext, IReadOnlySettings settings) | ||
| : IHandleMessages<MyMessage> | ||
| { | ||
| public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
| { | ||
| testContext.MessageId = context.MessageId.Replace(@"\", "-"); | ||
| testContext.EndpointNameOfReceivingEndpoint = settings.EndpointName(); | ||
|
|
||
| if (testContext.RetryCount < 3) | ||
| { | ||
| Console.Out.WriteLine("Throwing exception"); | ||
| throw new Exception("Simulated exception"); | ||
| } | ||
|
|
||
| Console.Out.WriteLine("Handling message"); | ||
|
|
||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class MyMessage : ICommand | ||
| { | ||
| public string Name { get; set; } | ||
| } | ||
|
|
||
| class MyContext : ScenarioContext | ||
| { | ||
| public string MessageId { get; set; } | ||
|
|
||
| public string EndpointNameOfReceivingEndpoint { get; set; } | ||
|
|
||
| public string UniqueMessageId => DeterministicGuid.MakeId(MessageId, EndpointNameOfReceivingEndpoint).ToString(); | ||
| public int RetryCount { get; set; } | ||
| } | ||
| } | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
src/ServiceControl.MultiInstance.AcceptanceTests/Recoverability/WhenRetryingWithEdit.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,92 @@ | ||
| namespace ServiceControl.MultiInstance.AcceptanceTests.Recoverability; | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using AcceptanceTesting; | ||
| using AcceptanceTesting.EndpointTemplates; | ||
| using MessageFailures; | ||
| using NServiceBus; | ||
| using NServiceBus.AcceptanceTesting; | ||
| using NServiceBus.Settings; | ||
| using NUnit.Framework; | ||
| using TestSupport; | ||
| using ServiceControl.Infrastructure; | ||
|
|
||
| class WhenRetryingWithEdit : WhenRetrying | ||
| { | ||
| [Test] | ||
| public async Task ShouldCreateNewMessageAndResolveEditedMessage() | ||
| { | ||
| CustomServiceControlPrimarySettings = s => { s.AllowMessageEditing = true; }; | ||
|
|
||
| await Define<MyContext>() | ||
| .WithEndpoint<FailureEndpoint>(b => | ||
| b.When(bus => bus.SendLocal(new MyMessage { Password = "Bad password!" })).DoNotFailOnErrorMessages()) | ||
| .Done(async c => | ||
| { | ||
| if (!c.ErrorRetried) | ||
| { | ||
| var failedMessage = await GetFailedMessage(c.UniqueMessageId, ServiceControlInstanceName, | ||
| FailedMessageStatus.Unresolved); | ||
| if (!failedMessage.HasResult) | ||
| { | ||
| return false; // No failed message yet | ||
| } | ||
|
|
||
| await this.Post<object>($"/api/edit/{failedMessage.Item.UniqueMessageId}", | ||
| new | ||
| { | ||
| MessageBody = "{ \"Password\": \"VerySecretPassword\" }", | ||
| MessageHeaders = failedMessage.Item.ProcessingAttempts[^1].Headers | ||
| }, null, | ||
| ServiceControlInstanceName); | ||
| c.ErrorRetried = true; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| var failedResolvedMessage = await GetFailedMessage(c.UniqueMessageId, ServiceControlInstanceName, FailedMessageStatus.Resolved); | ||
|
|
||
| return failedResolvedMessage.HasResult; // If there is a result it means the message was resolved | ||
| }) | ||
| .Run(TimeSpan.FromMinutes(2)); | ||
| } | ||
|
|
||
| class FailureEndpoint : EndpointConfigurationBuilder | ||
| { | ||
| public FailureEndpoint() => EndpointSetup<DefaultServerWithoutAudit>(c => { c.NoRetries(); }); | ||
|
|
||
| public class MyMessageHandler(MyContext testContext, IReadOnlySettings settings) : IHandleMessages<MyMessage> | ||
| { | ||
| public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
| { | ||
| if (message.Password == "VerySecretPassword") | ||
| { | ||
| Console.Out.WriteLine("Handling message"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| testContext.MessageId = context.MessageId.Replace(@"\", "-"); | ||
| testContext.EndpointNameOfReceivingEndpoint = settings.EndpointName(); | ||
|
|
||
| Console.Out.WriteLine("Throwing exception"); | ||
| throw new Exception("Simulated exception"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class MyMessage : ICommand | ||
| { | ||
| public string Password { get; set; } | ||
| } | ||
|
|
||
| class MyContext : ScenarioContext | ||
| { | ||
| public string MessageId { get; set; } | ||
|
|
||
| public string EndpointNameOfReceivingEndpoint { get; set; } | ||
|
|
||
| public string UniqueMessageId => DeterministicGuid.MakeId(MessageId, EndpointNameOfReceivingEndpoint).ToString(); | ||
| public bool ErrorRetried { get; set; } | ||
| } | ||
| } |
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
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.