Skip to content

Commit ff5de06

Browse files
committed
add DebugOnly tests
1 parent 0221609 commit ff5de06

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

.ci/test.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ dotnet test tests\SideBySide\SideBySide.csproj -c Release
2424
if ($LASTEXITCODE -ne 0){
2525
exit $LASTEXITCODE;
2626
}
27+
echo "Executing Debug Only tests"
28+
dotnet test tests\SideBySide\SideBySide.csproj -c Debug --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
29+
if ($LASTEXITCODE -ne 0){
30+
exit $LASTEXITCODE;
31+
}
2732

2833
echo "Executing tests with Compression, No SSL"
2934
Copy-Item -Force .ci\config\config.compression.json tests\SideBySide\config.json

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ script:
1818
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp1.1.1
1919
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
2020
- echo 'Executing tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
21+
- echo 'Executing Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp1.1.1 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
2122
- echo 'Executing tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
2223
- echo 'Executing tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
2324
- echo 'Executing tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1

src/MySqlConnector/MySqlClient/ConnectionPool.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ private ConnectionPool(ConnectionSettings cs)
215215
}
216216

217217
static readonly ConcurrentDictionary<string, ConnectionPool> s_pools = new ConcurrentDictionary<string, ConnectionPool>();
218+
#if DEBUG
219+
static readonly TimeSpan ReaperInterval = TimeSpan.FromSeconds(1);
220+
#else
218221
static readonly TimeSpan ReaperInterval = TimeSpan.FromMinutes(1);
222+
#endif
219223
static readonly Task Reaper = Task.Run(async () => {
220224
while (true)
221225
{

src/MySqlConnector/MySqlConnector.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.3.0" />
3737
</ItemGroup>
3838

39+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
40+
<DefineConstants>DEBUG</DefineConstants>
41+
</PropertyGroup>
42+
3943
<ItemGroup>
4044
<Compile Update="MySqlClient\MySqlCommand.cs">
4145
<SubType>Component</SubType>

tests/SideBySide/DebugOnlyTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using MySql.Data.MySqlClient;
5+
using Xunit;
6+
7+
namespace SideBySide
8+
{
9+
public class DebugOnlyTests : IClassFixture<DatabaseFixture>
10+
{
11+
12+
[Theory]
13+
[InlineData(1u, 3u, 0u, 5u)]
14+
[InlineData(1u, 3u, 3u, 5u)]
15+
public async Task ConnectionLifeTime(uint idleTimeout, uint delaySeconds, uint minPoolSize, uint maxPoolSize)
16+
{
17+
var csb = AppConfig.CreateConnectionStringBuilder();
18+
csb.Pooling = true;
19+
csb.MinimumPoolSize = minPoolSize;
20+
csb.MaximumPoolSize = maxPoolSize;
21+
csb.ConnectionIdleTimeout = idleTimeout;
22+
HashSet<int> serverThreadIdsBegin = new HashSet<int>();
23+
HashSet<int> serverThreadIdsEnd = new HashSet<int>();
24+
25+
async Task OpenConnections(uint numConnections, HashSet<int> serverIdSet)
26+
{
27+
using (var connection = new MySqlConnection(csb.ConnectionString))
28+
{
29+
await connection.OpenAsync();
30+
serverIdSet.Add(connection.ServerThread);
31+
if (--numConnections <= 0)
32+
return;
33+
await OpenConnections(numConnections, serverIdSet);
34+
}
35+
}
36+
37+
await OpenConnections(maxPoolSize, serverThreadIdsBegin);
38+
await Task.Delay(TimeSpan.FromSeconds(delaySeconds));
39+
await OpenConnections(maxPoolSize, serverThreadIdsEnd);
40+
41+
serverThreadIdsEnd.IntersectWith(serverThreadIdsBegin);
42+
Assert.Equal((int)minPoolSize, serverThreadIdsEnd.Count);
43+
}
44+
45+
}
46+
}

tests/SideBySide/SideBySide.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
<PackageReference Include="MySql.Data" Version="6.9.8" />
4242
</ItemGroup>
4343

44+
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
45+
<Compile Remove="DebugOnlyTests.cs" />
46+
</ItemGroup>
47+
4448
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
4549
<Reference Include="System" />
4650
<Reference Include="Microsoft.CSharp" />

0 commit comments

Comments
 (0)