-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathDlqMonitorTests.cs
92 lines (79 loc) · 3.66 KB
/
DlqMonitorTests.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
��using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection.PortableExecutable;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Lambda.TestTool.Runtime;
using Xunit;
using Amazon.SQS;
using Amazon.SQS.Model;
namespace Amazon.Lambda.TestTool.Tests
{
public class DlqMonitorTests
{
[Fact]
public async Task DlqIntegTest()
{
if (!TestUtils.ProfileTestsEnabled)
return;
const int WAIT_TIME = 5000;
var queueName = "local-dlq-list-queue-test-" + DateTime.Now.Ticks;
using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
{
var createResponse = await client.CreateQueueAsync(new CreateQueueRequest {QueueName = queueName});
await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);
try
{
var configFile = TestUtils.GetLambdaFunctionSourceFile("ToUpperFunc", "stream-function.json");
var buildPath = TestUtils.GetLambdaFunctionBuildPath("ToUpperFunc");
var configInfo = LambdaDefaultsConfigFileParser.LoadFromFile(configFile);
var runtime = LocalLambdaRuntime.Initialize(buildPath);
var function = runtime.LoadLambdaFunctions(configInfo.FunctionInfos)[0];
var monitor = new DlqMonitor(runtime, function, TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);
monitor.Start();
await client.SendMessageAsync(new SendMessageRequest
{
QueueUrl = createResponse.QueueUrl,
MessageBody = "\"testing dlq\""
});
Thread.Sleep(WAIT_TIME);
var logs = monitor.FetchNewLogs();
Assert.Single(logs);
Assert.Contains("testing dlq", logs[0].Logs);
Assert.NotNull(logs[0].ReceiptHandle);
Assert.NotEqual(DateTime.MinValue, logs[0].ProcessTime);
logs = monitor.FetchNewLogs();
Assert.Equal(0, logs.Count);
await client.SendMessageAsync(new SendMessageRequest
{
QueueUrl = createResponse.QueueUrl,
MessageBody = "\"testing dlq1\""
});
await client.SendMessageAsync(new SendMessageRequest
{
QueueUrl = createResponse.QueueUrl,
MessageBody = "\"testing dlq2\""
});
Thread.Sleep(WAIT_TIME);
logs = monitor.FetchNewLogs();
Assert.Equal(2, logs.Count);
monitor.Stop();
Thread.Sleep(WAIT_TIME);
await client.SendMessageAsync(new SendMessageRequest
{
QueueUrl = createResponse.QueueUrl,
MessageBody = "\"testing dlq3\""
});
Thread.Sleep(WAIT_TIME);
logs = monitor.FetchNewLogs();
Assert.Equal(0, logs.Count);
}
finally
{
await client.DeleteQueueAsync(createResponse.QueueUrl);
}
}
}
}
}