-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathIssue2430Tests.cs
More file actions
49 lines (42 loc) · 1.72 KB
/
Issue2430Tests.cs
File metadata and controls
49 lines (42 loc) · 1.72 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
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace StackExchange.Redis.Tests.Issues
{
public class Issue2430Tests : TestBase
{
public Issue2430Tests(ITestOutputHelper output) : base(output) { }
[Fact]
public void Execute()
{
var options = new ConfigurationOptions()
{
AbortOnConnectFail = false,
ConnectTimeout = 1,
ConnectRetry = 0,
SyncTimeout = 1,
AllowAdmin = true,
EndPoints = { GetConfiguration() },
};
using var conn = ConnectionMultiplexer.Connect(options, Writer);
var db = conn.GetDatabase();
// Disconnect and don't allow re-connection
conn.AllowConnect = false;
var server = conn.GetServerSnapshot()[0];
server.SimulateConnectionFailure(SimulatedFailureType.All);
// Increasing the number of backlog items increases the chance of a concurrency issue occurring
var backlogTasks = new Task[100000];
for (int i = 0; i < backlogTasks.Length; i++)
backlogTasks[i] = db.PingAsync();
Assert.True(Task.WaitAny(backlogTasks, 5000) != -1, "Timeout.");
conn.Dispose();
foreach (var task in backlogTasks)
{
Assert.True(task.IsCompleted, "Not completed.");
Assert.True(task.IsFaulted, "Not faulted.");
Assert.True(task.Exception!.InnerException is RedisTimeoutException or RedisConnectionException or ObjectDisposedException, $"Wrong exception: {task.Exception.InnerException.Message}");
}
}
}
}