StackExchange.Redis 系列 12:Testing 套件说明

  • 本系列博文是“伪”官方文档翻译,并非完全将官方文档进行翻译,而是我在查阅、测试原始文档并转换为自己东西后进行的“准”翻译。

  • 原始文档见此:https://stackexchange.github.io/StackExchange.Redis/

  • 本系列本博文基于 redis 5.0.6,系列中部分博文跟官方文档有出入,有不同见解 / 说明不当的地方,还请大家不吝拍砖。

StackExchange.Redis 为 windows 环境提供了测试套件,截至本文发布前,作者尚未正式发布跨平台的套件信息。

StackExchange.Redis 提供的单元和继承测试很简单,有 2 个主要步骤:

  1. 开启服务器

  2. 运行测试

  • 测试默认使用本机 Redis 服务(127.0.0.1),你可以修改 json 配置来自定义。

1
2
3
4
5
{
"RunLongRunning": true,
"MasterServer": "192.168.10.5",
"MasterPort": 2333
}

你可以从 github 中获取 json 配置:配置文件路径见此

  • 目前支持的配置信息如下,你可以 从这里 获取最新版本。

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
public class Config
{
public bool UseSharedConnection { get; set; } = true;
public bool RunLongRunning { get; set; }
public bool LogToConsole { get; set; }

public string MasterServer { get; set; } = "127.0.0.1";
public int MasterPort { get; set; } = 6379;
public string MasterServerAndPort => MasterServer + ":" + MasterPort.ToString();

public string SlaveServer { get; set; } = "127.0.0.1";
public int SlavePort { get; set; } = 6380;
public string SlaveServerAndPort => SlaveServer + ":" + SlavePort.ToString();

public string SecureServer { get; set; } = "127.0.0.1";
public int SecurePort { get; set; } = 6381;
public string SecurePassword { get; set; } = "changeme";
public string SecureServerAndPort => SecureServer + ":" + SecurePort.ToString();

// Separate servers for failover tests, so they don't wreak havoc on all others
public string FailoverMasterServer { get; set; } = "127.0.0.1";
public int FailoverMasterPort { get; set; } = 6382;
public string FailoverMasterServerAndPort => FailoverMasterServer + ":" + FailoverMasterPort.ToString();

public string FailoverSlaveServer { get; set; } = "127.0.0.1";
public int FailoverSlavePort { get; set; } = 6383;
public string FailoverSlaveServerAndPort => FailoverSlaveServer + ":" + FailoverSlavePort.ToString();

public string IPv4Server { get; set; } = "127.0.0.1";
public int IPv4Port { get; set; } = 6379;
public string IPv6Server { get; set; } = "::1";
public int IPv6Port { get; set; } = 6379;

public string RemoteServer { get; set; } = "127.0.0.1";
public int RemotePort { get; set; } = 6379;
public string RemoteServerAndPort => RemoteServer + ":" + RemotePort.ToString();

public string SentinelServer { get; set; } = "127.0.0.1";
public int SentinelPort { get; set; } = 26379;
public string SentinelSeviceName { get; set; } = "mymaster";

public string ClusterServer { get; set; } = "127.0.0.1";
public int ClusterStartPort { get; set; } = 7000;
public int ClusterServerCount { get; set; } = 6;

public string SslServer { get; set; }
public int SslPort { get; set; }

public string RedisLabsSslServer { get; set; }
public int RedisLabsSslPort { get; set; } = 6379;
public string RedisLabsPfxPath { get; set; }

public string AzureCacheServer { get; set; }
public string AzureCachePassword { get; set; }

public string SSDBServer { get; set; }
public int SSDBPort { get; set; } = 8888;
}
  • 注意,如果不指定特定的服务器,相关测试应当跳过(因为结果会不确定)。

在 windows 下测试

默认情况下,测试过程会作为构建的一部分,你可以在 repository 的根目录运行以下命令:

1
.\build.cmd -BuildNumber local

也可以使用更多其他选项:

1
2
3
4
dotnet build
.\RedisConfigs\start-all.cmd
cd StackExchange.Redis.Tests
dotnet xunit