forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPoolManagerTests.cs
More file actions
79 lines (70 loc) · 2.34 KB
/
PoolManagerTests.cs
File metadata and controls
79 lines (70 loc) · 2.34 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using NUnit.Framework;
namespace Npgsql.Tests;
[NonParallelizable]
class PoolManagerTests : TestBase
{
[Test]
public void With_canonical_connection_string()
{
var connString = new NpgsqlConnectionStringBuilder(ConnectionString).ToString();
using (var conn = new NpgsqlConnection(connString))
conn.Open();
var connString2 = new NpgsqlConnectionStringBuilder(ConnectionString)
{
ApplicationName = "Another connstring"
}.ToString();
using (var conn = new NpgsqlConnection(connString2))
conn.Open();
}
#if DEBUG
[Test]
public void Many_pools()
{
PoolManager.Reset();
for (var i = 0; i < 15; i++)
{
var connString = new NpgsqlConnectionStringBuilder(ConnectionString)
{
ApplicationName = "App" + i
}.ToString();
using var conn = new NpgsqlConnection(connString);
conn.Open();
}
PoolManager.Reset();
}
#endif
[Test]
public void ClearAllPools()
{
using (var conn = new NpgsqlConnection(ConnectionString))
conn.Open();
// Now have one connection in the pool
Assert.That(PoolManager.Pools.TryGetValue(ConnectionString, out var pool), Is.True);
Assert.That(pool!.Statistics.Idle, Is.EqualTo(1));
NpgsqlConnection.ClearAllPools();
Assert.That(pool.Statistics.Idle, Is.Zero);
Assert.That(pool.Statistics.Total, Is.Zero);
}
[Test]
public void ClearAllPools_with_busy()
{
NpgsqlDataSource? pool;
using (var conn = new NpgsqlConnection(ConnectionString))
{
conn.Open();
using (var anotherConn = new NpgsqlConnection(ConnectionString))
anotherConn.Open();
// We have one idle, one busy
NpgsqlConnection.ClearAllPools();
Assert.That(PoolManager.Pools.TryGetValue(ConnectionString, out pool), Is.True);
Assert.That(pool!.Statistics.Idle, Is.Zero);
Assert.That(pool.Statistics.Total, Is.EqualTo(1));
}
Assert.That(pool.Statistics.Idle, Is.Zero);
Assert.That(pool.Statistics.Total, Is.Zero);
}
[SetUp]
public void Setup() => PoolManager.Reset();
[TearDown]
public void Teardown() => PoolManager.Reset();
}