forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoolManagerTests.cs
More file actions
77 lines (69 loc) · 2.4 KB
/
PoolManagerTests.cs
File metadata and controls
77 lines (69 loc) · 2.4 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
using NUnit.Framework;
namespace Npgsql.Tests
{
[NonParallelizable]
class PoolManagerTests : TestBase
{
[Test]
public void WithCanonicalConnString()
{
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 ManyPools()
{
PoolManager.Reset();
for (var i = 0; i < PoolManager.InitialPoolsSize + 1; i++)
{
var connString = new NpgsqlConnectionStringBuilder(ConnectionString)
{
ApplicationName = "App" + i
}.ToString();
using (var conn = new NpgsqlConnection(connString))
conn.Open();
}
PoolManager.Reset();
}
#endif
[Test]
public void ClearAll()
{
using (OpenConnection()) {}
// Now have one connection in the pool
Assert.That(PoolManager.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.Open, Is.Zero);
}
[Test]
public void ClearAllWithBusy()
{
ConnectorPool? pool;
using (OpenConnection())
{
using (OpenConnection()) { }
// We have one idle, one busy
NpgsqlConnection.ClearAllPools();
Assert.That(PoolManager.TryGetValue(ConnectionString, out pool), Is.True);
Assert.That(pool!.Statistics.Idle, Is.Zero);
Assert.That(pool.Statistics.Open, Is.EqualTo(1));
}
Assert.That(pool.Statistics.Idle, Is.Zero);
Assert.That(pool.Statistics.Open, Is.Zero);
}
[SetUp]
public void Setup() => PoolManager.Reset();
[TearDown]
public void Teardown() => PoolManager.Reset();
}
}