Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added delivery timeout parameter to saga fixture deliver method
- Loading branch information
1 parent
b330558
commit 95efa82
Showing
12 changed files
with
286 additions
and
27 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
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,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Rebus.Tests.Contracts.Extensions | ||
{ | ||
public class Range<T> | ||
{ | ||
public Range(T from, T to) | ||
{ | ||
if (from == null) throw new ArgumentNullException(nameof(@from)); | ||
if (to == null) throw new ArgumentNullException(nameof(to)); | ||
From = from; | ||
To = to; | ||
} | ||
|
||
public T From { get; } | ||
public T To { get; } | ||
} | ||
|
||
public static class RangeExtensions | ||
{ | ||
public static Range<T> To<T>(this T from, T to) | ||
{ | ||
return new Range<T>(from, to); | ||
} | ||
|
||
public static IEnumerable<DateTime> GetIntervals(this Range<DateTime> timeRange, TimeSpan interval) | ||
{ | ||
for (var time = timeRange.From; time < timeRange.To; time = time + interval) | ||
{ | ||
yield return time; | ||
} | ||
} | ||
} | ||
} |
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
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,48 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Rebus.Messages; | ||
using Rebus.Transport; | ||
|
||
namespace Rebus.Tests.Contracts.Utilities | ||
{ | ||
public class IntroducerOfLatency : ITransport | ||
{ | ||
readonly ITransport _innerTransport; | ||
readonly int? _sendLatencyMs; | ||
readonly int? _receiveLatencyMs; | ||
|
||
public IntroducerOfLatency(ITransport innerTransport, int? sendLatencyMs = null, int? receiveLatencyMs = null) | ||
{ | ||
_innerTransport = innerTransport; | ||
_sendLatencyMs = sendLatencyMs; | ||
_receiveLatencyMs = receiveLatencyMs; | ||
} | ||
|
||
public void CreateQueue(string address) | ||
{ | ||
_innerTransport.CreateQueue(address); | ||
} | ||
|
||
public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context) | ||
{ | ||
if (_sendLatencyMs.HasValue) | ||
{ | ||
await Task.Delay(_sendLatencyMs.Value); | ||
} | ||
|
||
await _innerTransport.Send(destinationAddress, message, context); | ||
} | ||
|
||
public async Task<TransportMessage> Receive(ITransactionContext context, CancellationToken cancellationToken) | ||
{ | ||
if (_receiveLatencyMs.HasValue) | ||
{ | ||
await Task.Delay(_receiveLatencyMs.Value, cancellationToken); | ||
} | ||
|
||
return await _innerTransport.Receive(context, cancellationToken); | ||
} | ||
|
||
public string Address => _innerTransport.Address; | ||
} | ||
} |
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,140 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Rebus.Activation; | ||
using Rebus.Backoff; | ||
using Rebus.Config; | ||
using Rebus.Logging; | ||
using Rebus.Tests.Contracts; | ||
using Rebus.Tests.Contracts.Extensions; | ||
using Rebus.Tests.Contracts.Utilities; | ||
using Rebus.Transport; | ||
using Rebus.Transport.InMem; | ||
using Rebus.Workers; | ||
#pragma warning disable 1998 | ||
|
||
namespace Rebus.Tests.Backoff | ||
{ | ||
[TestFixture] | ||
public class TestBackoffBehaviorWhenBusy : FixtureBase | ||
{ | ||
BuiltinHandlerActivator _activator; | ||
BackoffSnitch _snitch; | ||
|
||
protected override void SetUp() | ||
{ | ||
_activator = Using(new BuiltinHandlerActivator()); | ||
|
||
_snitch = new BackoffSnitch(); | ||
|
||
Configure.With(_activator) | ||
.Logging(l => l.Console(LogLevel.Info)) | ||
.Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "busy-test")) | ||
.Options(o => | ||
{ | ||
o.SetNumberOfWorkers(1); | ||
o.SetMaxParallelism(500); | ||
o.SetBackoffTimes(TimeSpan.FromSeconds(0.2)); | ||
// install the snitch | ||
o.Decorate<ISyncBackoffStrategy>(c => | ||
{ | ||
var syncBackoffStrategy = c.Get<ISyncBackoffStrategy>(); | ||
_snitch.SyncBackoffStrategy = syncBackoffStrategy; | ||
return _snitch; | ||
}); | ||
o.Decorate<ITransport>(c => | ||
{ | ||
var transport = c.Get<ITransport>(); | ||
return new IntroducerOfLatency(transport, receiveLatencyMs: 10); | ||
}); | ||
}) | ||
.Start(); | ||
} | ||
|
||
[TestCase(100000)] | ||
public async Task DoesNotBackOffAtAllWhenBusy(int messageCount) | ||
{ | ||
var counter = new SharedCounter(messageCount); | ||
|
||
_activator.Handle<string>(async str => | ||
{ | ||
await Task.Delay(1); | ||
counter.Decrement(); | ||
}); | ||
|
||
var startTime = DateTime.UtcNow; | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(5)); | ||
|
||
Printt("Sending 100k msgs"); | ||
|
||
await Task.WhenAll(Enumerable.Range(0, messageCount) | ||
.Select(i => _activator.Bus.SendLocal($"THIS IS MESSAGE {i}"))); | ||
|
||
Printt("Receiving them..."); | ||
|
||
_activator.Bus.Advanced.Workers.SetNumberOfWorkers(1); | ||
|
||
counter.WaitForResetEvent(60); | ||
|
||
Printt("Done... waiting a little extra"); | ||
await Task.Delay(TimeSpan.FromSeconds(5)); | ||
|
||
var stopTime = DateTime.UtcNow; | ||
|
||
var waitsPerSecond = _snitch.WaitTimes | ||
.GroupBy(t => t.RoundTo(TimeSpan.FromSeconds(1))) | ||
.ToDictionary(g => g.Key, g => g.Count()); | ||
|
||
var waitNoMessagesPerSecond = _snitch.WaitNoMessageTimes | ||
.GroupBy(t => t.RoundTo(TimeSpan.FromSeconds(1))) | ||
.ToDictionary(g => g.Key, g => g.Count()); | ||
|
||
var seconds = startTime.RoundTo(TimeSpan.FromSeconds(1)).To(stopTime.RoundTo(TimeSpan.FromSeconds(1))) | ||
.GetIntervals(TimeSpan.FromSeconds(1)); | ||
|
||
Console.WriteLine(string.Join(Environment.NewLine, | ||
seconds.Select(time => $"{time}: {new string('.', waitsPerSecond.GetValueOrDefault(time))}{new string('*', waitNoMessagesPerSecond.GetValueOrDefault(time))}"))); | ||
} | ||
|
||
class BackoffSnitch : ISyncBackoffStrategy | ||
{ | ||
readonly ConcurrentQueue<DateTime> _waitTimes = new ConcurrentQueue<DateTime>(); | ||
readonly ConcurrentQueue<DateTime> _waitNoMessageTimes = new ConcurrentQueue<DateTime>(); | ||
|
||
public ISyncBackoffStrategy SyncBackoffStrategy { get; set; } | ||
|
||
public IEnumerable<DateTime> WaitTimes => _waitTimes; | ||
public IEnumerable<DateTime> WaitNoMessageTimes => _waitNoMessageTimes; | ||
|
||
public void Reset() | ||
{ | ||
SyncBackoffStrategy.Reset(); | ||
} | ||
|
||
public void WaitNoMessage() | ||
{ | ||
_waitNoMessageTimes.Enqueue(DateTime.UtcNow); | ||
SyncBackoffStrategy.WaitNoMessage(); | ||
} | ||
|
||
public void Wait() | ||
{ | ||
_waitTimes.Enqueue(DateTime.UtcNow); | ||
SyncBackoffStrategy.Wait(); | ||
} | ||
|
||
public void WaitError() | ||
{ | ||
SyncBackoffStrategy.WaitError(); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.