-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/Issue2994-CircuitBreaker-Timeout' into hotfix-5.2.9
- Loading branch information
Showing
5 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
57 changes: 57 additions & 0 deletions
57
src/NServiceBus.AcceptanceTests/Timeouts/TemporarilyUnavailableTimeoutPersister.cs
This file contains 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,57 @@ | ||
namespace NServiceBus.AcceptanceTests.Timeouts | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Timeout.Core; | ||
|
||
class TemporarilyUnavailableTimeoutPersister : IPersistTimeouts | ||
{ | ||
public int SecondsToWait { get; set; } | ||
static bool isAvailable = false; | ||
DateTime NextChangeTime; | ||
|
||
public TemporarilyUnavailableTimeoutPersister() | ||
{ | ||
NextChangeTime = DateTime.Now.AddSeconds(SecondsToWait); | ||
} | ||
|
||
private void ThrowExceptionUntilWait() | ||
{ | ||
if (NextChangeTime <= DateTime.Now) | ||
{ | ||
NextChangeTime = DateTime.Now.AddSeconds(SecondsToWait); | ||
isAvailable = !isAvailable; | ||
} | ||
|
||
if (!isAvailable) | ||
{ | ||
throw new Exception("Persister is temporarily unavailable"); | ||
} | ||
} | ||
|
||
public IEnumerable<Tuple<string, DateTime>> GetNextChunk(DateTime startSlice, out DateTime nextTimeToRunQuery) | ||
{ | ||
ThrowExceptionUntilWait(); | ||
nextTimeToRunQuery = DateTime.Now.AddSeconds(2); | ||
return Enumerable.Empty<Tuple<string, DateTime>>().ToList(); | ||
} | ||
|
||
public void Add(TimeoutData timeout) | ||
{ | ||
ThrowExceptionUntilWait(); | ||
} | ||
|
||
public bool TryRemove(string timeoutId, out TimeoutData timeoutData) | ||
{ | ||
ThrowExceptionUntilWait(); | ||
timeoutData = null; | ||
return true; | ||
} | ||
|
||
public void RemoveTimeoutBy(Guid sagaId) | ||
{ | ||
ThrowExceptionUntilWait(); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/NServiceBus.AcceptanceTests/Timeouts/When_timeout_storage_is_unavailable_temporarily.cs
This file contains 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,88 @@ | ||
namespace NServiceBus.AcceptanceTests.Timeouts | ||
{ | ||
using System; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using Features; | ||
using Timeout.Core; | ||
using NUnit.Framework; | ||
|
||
class When_timeout_storage_is_unavailable_temporarily : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Endpoint_should_start() | ||
{ | ||
var context = new TestContext(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<EndpointWithFlakyTimeoutPersister>() | ||
.Done(c => c.EndpointsStarted) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.EndpointsStarted); | ||
} | ||
|
||
|
||
[Test] | ||
public void Endpoint_should_not_shutdown() | ||
{ | ||
var context = new TestContext{SecondsToWait = 10}; | ||
var stopTime = DateTime.Now.AddSeconds(45); | ||
|
||
Scenario.Define(context) | ||
.AllowExceptions(ex => ex.Message.Contains("Persister is temporarily unavailable")) | ||
.WithEndpoint<EndpointWithFlakyTimeoutPersister>(b => | ||
{ | ||
b.CustomConfig(busConfig => | ||
{ | ||
busConfig.DefineCriticalErrorAction((s, ex) => | ||
{ | ||
context.FatalErrorOccurred = true; | ||
}); | ||
}); | ||
}) | ||
.Done(c => context.FatalErrorOccurred || stopTime <= DateTime.Now) | ||
.Run(); | ||
|
||
Assert.IsFalse(context.FatalErrorOccurred, "Circuit breaker was trigged too soon."); | ||
} | ||
|
||
public class TestContext : ScenarioContext | ||
{ | ||
public int SecondsToWait { get; set; } | ||
public bool FatalErrorOccurred { get; set; } | ||
} | ||
|
||
[Serializable] | ||
public class MyMessage : IMessage { } | ||
|
||
public class EndpointWithFlakyTimeoutPersister : EndpointConfigurationBuilder | ||
{ | ||
public TestContext TestContext { get; set; } | ||
public EndpointWithFlakyTimeoutPersister() | ||
{ | ||
EndpointSetup<DefaultServer>(config => | ||
{ | ||
config.EnableFeature<TimeoutManager>(); | ||
config.Transactions().DisableDistributedTransactions(); | ||
config.SuppressOutdatedTimeoutPersistenceWarning(); | ||
}); | ||
} | ||
|
||
class Initalizer : Feature | ||
{ | ||
public Initalizer() | ||
{ | ||
EnableByDefault(); | ||
} | ||
|
||
protected override void Setup(FeatureConfigurationContext context) | ||
{ | ||
context.Container | ||
.ConfigureComponent<TemporarilyUnavailableTimeoutPersister>(DependencyLifecycle.SingleInstance) | ||
.ConfigureProperty(tp => tp.SecondsToWait, 10); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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