Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8d9d339

Browse files
committed
Add new ServiceStack.Redis.Tests.Sentinel project and move all Sentinel tests over
1 parent 91ae486 commit 8d9d339

11 files changed

Lines changed: 202 additions & 12 deletions

src/ServiceStack.Redis.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Redis.Tests",
2020
EndProject
2121
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console.Tests", "..\tests\Console.Tests\Console.Tests.csproj", "{8368C965-B4F6-4263-9ABB-731A175B2E77}"
2222
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Redis.Tests.Sentinel", "..\tests\ServiceStack.Redis.Tests.Sentinel\ServiceStack.Redis.Tests.Sentinel.csproj", "{91C55091-A946-49B5-9517-8794EBCC5784}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -63,6 +65,15 @@ Global
6365
{8368C965-B4F6-4263-9ABB-731A175B2E77}.Signed|Any CPU.ActiveCfg = Release|Any CPU
6466
{8368C965-B4F6-4263-9ABB-731A175B2E77}.Signed|Any CPU.Build.0 = Release|Any CPU
6567
{8368C965-B4F6-4263-9ABB-731A175B2E77}.Signed|x86.ActiveCfg = Release|Any CPU
68+
{91C55091-A946-49B5-9517-8794EBCC5784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69+
{91C55091-A946-49B5-9517-8794EBCC5784}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{91C55091-A946-49B5-9517-8794EBCC5784}.Debug|x86.ActiveCfg = Debug|Any CPU
71+
{91C55091-A946-49B5-9517-8794EBCC5784}.Release|Any CPU.ActiveCfg = Release|Any CPU
72+
{91C55091-A946-49B5-9517-8794EBCC5784}.Release|Any CPU.Build.0 = Release|Any CPU
73+
{91C55091-A946-49B5-9517-8794EBCC5784}.Release|x86.ActiveCfg = Release|Any CPU
74+
{91C55091-A946-49B5-9517-8794EBCC5784}.Signed|Any CPU.ActiveCfg = Release|Any CPU
75+
{91C55091-A946-49B5-9517-8794EBCC5784}.Signed|Any CPU.Build.0 = Release|Any CPU
76+
{91C55091-A946-49B5-9517-8794EBCC5784}.Signed|x86.ActiveCfg = Release|Any CPU
6677
EndGlobalSection
6778
GlobalSection(SolutionProperties) = preSolution
6879
HideSolutionNode = FALSE

src/packages/repositories.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<repositories>
3+
<repository path="..\..\tests\ServiceStack.Redis.Tests.Sentinel\packages.config" />
34
<repository path="..\..\tests\ServiceStack.Redis.Tests\packages.config" />
45
</repositories>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ServiceStack.Redis.Tests.Sentinel")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ServiceStack.Redis.Tests.Sentinel")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d57d78f4-4b0b-40eb-a162-f6146e358294")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

tests/ServiceStack.Redis.Tests/Redis3SentinelSetupTests.cs renamed to tests/ServiceStack.Redis.Tests.Sentinel/Redis3SentinelSetupTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using NUnit.Framework;
22
using ServiceStack.Text;
33

4-
namespace ServiceStack.Redis.Tests
4+
namespace ServiceStack.Redis.Tests.Sentinel
55
{
6-
[Ignore("Ignore Sentinel Integration Tests")]
76
[TestFixture, Category("Integration")]
87
public class Redis3SentinelSetupTests
98
: RedisSentinelTestBase

tests/ServiceStack.Redis.Tests/RedisResolverTests.cs renamed to tests/ServiceStack.Redis.Tests.Sentinel/RedisResolverTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
using NUnit.Framework;
44
using ServiceStack.Text;
55

6-
namespace ServiceStack.Redis.Tests
6+
namespace ServiceStack.Redis.Tests.Sentinel
77
{
8-
[Ignore("Ignore Sentinel Integration Tests")]
98
[TestFixture]
109
public class RedisResolverTests
1110
: RedisSentinelTestBase

tests/ServiceStack.Redis.Tests/RedisSentinelTestBase.cs renamed to tests/ServiceStack.Redis.Tests.Sentinel/RedisSentinelTestBase.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using System.Threading;
55
using ServiceStack.Text;
66

7-
namespace ServiceStack.Redis.Tests
7+
namespace ServiceStack.Redis.Tests.Sentinel
88
{
99
public abstract class RedisSentinelTestBase
1010
{
11+
public const bool DisableLocalServers = true;
12+
1113
public const string MasterName = "mymaster";
1214
public const string GCloudMasterName = "master";
1315

@@ -70,7 +72,6 @@ public static RedisSentinel CreateGCloudSentinel()
7072
return sentinel;
7173
}
7274

73-
7475
public static void StartRedisServer(int port)
7576
{
7677
var pInfo = new ProcessStartInfo
@@ -103,6 +104,9 @@ public static void StartRedisSentinel(int port)
103104

104105
public static void StartAllRedisServers(int waitMs = 1500)
105106
{
107+
if (DisableLocalServers)
108+
return;
109+
106110
foreach (var port in RedisPorts)
107111
{
108112
StartRedisServer(port);
@@ -113,6 +117,9 @@ public static void StartAllRedisServers(int waitMs = 1500)
113117

114118
public static void StartAllRedisSentinels(int waitMs = 1500)
115119
{
120+
if (DisableLocalServers)
121+
return;
122+
116123
foreach (var port in RedisPorts)
117124
{
118125
StartRedisSentinel(port);
@@ -123,6 +130,9 @@ public static void StartAllRedisSentinels(int waitMs = 1500)
123130

124131
public static void ShutdownAllRedisServers()
125132
{
133+
if (DisableLocalServers)
134+
return;
135+
126136
foreach (var port in RedisPorts)
127137
{
128138
try
@@ -140,6 +150,9 @@ public static void ShutdownAllRedisServers()
140150

141151
public static void ShutdownAllRedisSentinels()
142152
{
153+
if (DisableLocalServers)
154+
return;
155+
143156
foreach (var port in SentinelPorts)
144157
{
145158
try

tests/ServiceStack.Redis.Tests/RedisSentinelTests.cs renamed to tests/ServiceStack.Redis.Tests.Sentinel/RedisSentinelTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
using ServiceStack.Text;
66
using Timer = System.Timers.Timer;
77

8-
namespace ServiceStack.Redis.Tests
8+
namespace ServiceStack.Redis.Tests.Sentinel
99
{
10-
[Ignore("Ignore Sentinel Integration Tests")]
1110
[TestFixture, Category("Integration")]
1211
public class RedisSentinelTests
1312
: RedisSentinelTestBase
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{91C55091-A946-49B5-9517-8794EBCC5784}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ServiceStack.Redis.Tests.Sentinel</RootNamespace>
11+
<AssemblyName>ServiceStack.Redis.Tests.Sentinel</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\src\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
36+
<HintPath>..\..\src\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
37+
<Private>True</Private>
38+
</Reference>
39+
<Reference Include="ServiceStack.Client">
40+
<HintPath>..\..\lib\ServiceStack.Client.dll</HintPath>
41+
</Reference>
42+
<Reference Include="ServiceStack.Common">
43+
<HintPath>..\..\lib\ServiceStack.Common.dll</HintPath>
44+
</Reference>
45+
<Reference Include="ServiceStack.Interfaces">
46+
<HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
47+
</Reference>
48+
<Reference Include="ServiceStack.Text">
49+
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
50+
</Reference>
51+
<Reference Include="System" />
52+
<Reference Include="System.Core" />
53+
<Reference Include="System.Xml.Linq" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="Microsoft.CSharp" />
56+
<Reference Include="System.Data" />
57+
<Reference Include="System.Xml" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<Compile Include="Properties\AssemblyInfo.cs" />
61+
<Compile Include="Redis3SentinelSetupTests.cs" />
62+
<Compile Include="RedisResolverTests.cs" />
63+
<Compile Include="RedisSentinelTestBase.cs" />
64+
<Compile Include="RedisSentinelTests.cs" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<None Include="packages.config" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<ProjectReference Include="..\..\src\ServiceStack.Redis\ServiceStack.Redis.csproj">
71+
<Project>{af99f19b-4c04-4f58-81ef-b092f1fcc540}</Project>
72+
<Name>ServiceStack.Redis</Name>
73+
</ProjectReference>
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
77+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
78+
<PropertyGroup>
79+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
80+
</PropertyGroup>
81+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
82+
</Target>
83+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
84+
Other similar extension points exist, see Microsoft.Common.targets.
85+
<Target Name="BeforeBuild">
86+
</Target>
87+
<Target Name="AfterBuild">
88+
</Target>
89+
-->
90+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="2.6.4" targetFramework="net45" />
4+
</packages>

tests/ServiceStack.Redis.Tests/PooledRedisClientManagerTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Linq;
45
using System.Threading;
56
using NUnit.Framework;
67
using ServiceStack.Text;
@@ -349,6 +350,47 @@ public void Does_block_ReadOnly_clients_pool()
349350
}
350351
}
351352

353+
[Test]
354+
public void Does_throw_TimeoutException_when_PoolTimeout_exceeded()
355+
{
356+
using (var manager = new PooledRedisClientManager(testReadWriteHosts, testReadOnlyHosts,
357+
new RedisClientManagerConfig
358+
{
359+
MaxWritePoolSize = 4,
360+
MaxReadPoolSize = 4,
361+
AutoStart = false,
362+
}))
363+
{
364+
manager.PoolTimeout = 100;
365+
366+
manager.Start();
367+
368+
var masters = 4.Times(i => manager.GetClient());
369+
370+
try
371+
{
372+
manager.GetClient();
373+
Assert.Fail("Should throw TimeoutException");
374+
}
375+
catch (TimeoutException ex)
376+
{
377+
Assert.That(ex.Message, Is.StringStarting("Redis Timeout expired."));
378+
}
379+
380+
var slaves = 4.Times(i => manager.GetReadOnlyClient());
381+
382+
try
383+
{
384+
manager.GetReadOnlyClient();
385+
Assert.Fail("Should throw TimeoutException");
386+
}
387+
catch (TimeoutException ex)
388+
{
389+
Assert.That(ex.Message, Is.StringStarting("Redis Timeout expired."));
390+
}
391+
}
392+
}
393+
352394
[Test]
353395
public void Can_support_64_threads_using_the_client_simultaneously()
354396
{

0 commit comments

Comments
 (0)