Repository navigation
Expand file tree
/
Copy pathPerRecipientLimitTests.cs
More file actions
74 lines (67 loc) · 2.11 KB
/
Copy pathPerRecipientLimitTests.cs
File metadata and controls
74 lines (67 loc) · 2.11 KB
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
using Xunit;
namespace MailLoadTester.Tests;
public sealed class PerRecipientLimitTests
{
private static MailTestOptions Opts(int max) => new(
From: "a@test.local",
Recipients: new[] { "same@test.local" },
SmtpHost: "127.0.0.1",
Port: 25,
Security: SmtpSecurity.None,
UseAuthentication: false,
Username: "",
Password: "",
MessageCount: 20,
IntervalMs: 0,
BatchMode: false,
BatchSize: 1,
BatchPauseSeconds: 0,
MaxConcurrency: 10,
Subject: "s",
Body: "b",
DisplayName: "n",
RandomTestData: false,
TestMode: false,
AllowedDomains: "",
HtmlBody: false,
Attachments: Array.Empty<string>(),
CustomHeaders: new Dictionary<string, string>(),
IgnoreCertificateErrors: false,
MaxRetries: 0,
DryRun: true,
EnableJitter: false,
EnablePerRecipientLimit: true,
MaxMessagesPerRecipient: max,
PerRecipientWindowMinutes: 60,
DetectGreylist: false,
EnableBurstMode: false,
EnableProgressiveBackoff: false,
EnableWarmup: false,
EnableSendingTimeWindow: false);
[Fact]
public void ConcurrentReserve_DoesNotExceedMax()
{
const int max = 3;
var pace = new SmartPaceController(Opts(max));
var ok = 0;
Parallel.For(0, 40, _ =>
{
if (pace.TryReserveRecipient("same@test.local"))
Interlocked.Increment(ref ok);
});
Assert.Equal(max, ok);
// Release all
for (int i = 0; i < max; i++)
pace.ReleaseRecipient("same@test.local");
Assert.True(pace.TryReserveRecipient("same@test.local"));
pace.CommitRecipient("same@test.local");
}
[Fact]
public void Commit_ConsumesReservation_AndCountsTowardLimit()
{
var pace = new SmartPaceController(Opts(1));
Assert.True(pace.TryReserveRecipient("same@test.local"));
pace.CommitRecipient("same@test.local");
Assert.False(pace.TryReserveRecipient("same@test.local"));
}
}