-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
DeferMessageTest.cs
71 lines (55 loc) · 2.07 KB
/
DeferMessageTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Amazon;
using Amazon.SQS;
using NUnit.Framework;
using Rebus.Activation;
using Rebus.AmazonSQS.Config;
using Rebus.Config;
using Rebus.Tests;
using Rebus.Tests.Extensions;
#pragma warning disable 1998
namespace Rebus.AmazonSQS.Tests
{
[TestFixture, Category(Category.AmazonSqs)]
public class DeferMessageTest : SqsFixtureBase
{
BuiltinHandlerActivator _activator;
RebusConfigurer _configurer;
protected override void SetUp()
{
var connectionInfo = AmazonSqsTransportFactory.ConnectionInfo;
var accessKeyId = connectionInfo.AccessKeyId;
var secretAccessKey = connectionInfo.SecretAccessKey;
var amazonSqsConfig = new AmazonSQSConfig
{
RegionEndpoint = RegionEndpoint.GetBySystemName(AmazonSqsTransportFactory.ConnectionInfo.RegionEndpoint)
};
var queueName = TestConfig.QueueName("defertest");
AmazonSqsManyMessagesTransportFactory.PurgeQueue(queueName);
_activator = Using(new BuiltinHandlerActivator());
_configurer = Configure.With(_activator)
.Transport(t => t.UseAmazonSqs(accessKeyId, secretAccessKey, amazonSqsConfig, queueName))
.Options(o => o.LogPipeline());
}
[Test]
public async Task CanDeferMessage()
{
var gotTheMessage = new ManualResetEvent(false);
var receiveTime = DateTime.MaxValue;
_activator.Handle<string>(async str =>
{
receiveTime = DateTime.UtcNow;
gotTheMessage.Set();
});
var bus = _configurer.Start();
var sendTime = DateTime.UtcNow;
await bus.Defer(TimeSpan.FromSeconds(10), "hej med dig!");
gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(20));
var elapsed = receiveTime - sendTime;
Assert.That(elapsed, Is.GreaterThan(TimeSpan.FromSeconds(8)));
}
}
}