Skip to content

Commit f104214

Browse files
committed
Move ConnectionLifeTime test.
This only tests the internal logic of the connector, so doesn't need to be run as a full integration test.
1 parent 1abb7b1 commit f104214

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

tests/MySqlConnector.Tests/ConnectionTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ public async Task UnpooledConnectionIsClosed()
6262
}
6363
}
6464

65+
[Theory]
66+
[InlineData(2u, 3u, true)]
67+
[InlineData(180u, 3u, false)]
68+
public async Task ConnectionLifeTime(uint lifeTime, uint delaySeconds, bool shouldTimeout)
69+
{
70+
m_csb.Pooling = true;
71+
m_csb.MinimumPoolSize = 0;
72+
m_csb.MaximumPoolSize = 1;
73+
m_csb.ConnectionLifeTime = lifeTime;
74+
int serverThread;
75+
76+
using (var connection = new MySqlConnection(m_csb.ConnectionString))
77+
{
78+
await connection.OpenAsync();
79+
serverThread = connection.ServerThread;
80+
await Task.Delay(TimeSpan.FromSeconds(delaySeconds));
81+
}
82+
83+
using (var connection = new MySqlConnection(m_csb.ConnectionString))
84+
{
85+
await connection.OpenAsync();
86+
if (shouldTimeout)
87+
Assert.NotEqual(serverThread, connection.ServerThread);
88+
else
89+
Assert.Equal(serverThread, connection.ServerThread);
90+
}
91+
}
92+
6593
private static async Task WaitForConditionAsync<T>(T expected, Func<T> getValue)
6694
{
6795
var sw = Stopwatch.StartNew();

tests/SideBySide/ConnectionPool.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -205,35 +205,6 @@ public async Task WaitTimeout()
205205
}
206206
}
207207

208-
[Theory]
209-
[InlineData(2u, 3u, true)]
210-
[InlineData(180u, 3u, false)]
211-
public async Task ConnectionLifeTime(uint lifeTime, uint delaySeconds, bool shouldTimeout)
212-
{
213-
var csb = AppConfig.CreateConnectionStringBuilder();
214-
csb.Pooling = true;
215-
csb.MinimumPoolSize = 0;
216-
csb.MaximumPoolSize = 1;
217-
csb.ConnectionLifeTime = lifeTime;
218-
int serverThread;
219-
220-
using (var connection = new MySqlConnection(csb.ConnectionString))
221-
{
222-
await connection.OpenAsync();
223-
serverThread = connection.ServerThread;
224-
await Task.Delay(TimeSpan.FromSeconds(delaySeconds));
225-
}
226-
227-
using (var connection = new MySqlConnection(csb.ConnectionString))
228-
{
229-
await connection.OpenAsync();
230-
if (shouldTimeout)
231-
Assert.NotEqual(serverThread, connection.ServerThread);
232-
else
233-
Assert.Equal(serverThread, connection.ServerThread);
234-
}
235-
}
236-
237208
[Fact]
238209
public async Task CharacterSet()
239210
{

0 commit comments

Comments
 (0)