Skip to content

Commit 5b1bbe9

Browse files
Add TimeoutTimer arg to TryGetConnection / idleTimeout to DbConnectionPoolGroupOptions in new idle-timeout tests
Main added a TimeoutTimer parameter to ChannelDbConnectionPool.TryGetConnection and WaitHandleDbConnectionPool.TryGetConnection while this branch was in flight. The new idle-timeout tests still used the old 3-arg form, causing CS7036 on net9.0. Also missed one DbConnectionPoolGroupOptions ctor call in ConcurrentCallers test.
1 parent abfa301 commit 5b1bbe9

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ public void IdleTimeout_StampedOnReturn()
10021002
var pool = ConstructPoolWithIdleTimeout(idleTimeoutSeconds: 3600);
10031003
SqlConnection owningConnection = new();
10041004
pool.TryGetConnection(owningConnection, taskCompletionSource: null,
1005+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10051006
out DbConnectionInternal? connection);
10061007
Assert.NotNull(connection);
10071008

@@ -1027,6 +1028,7 @@ public void IdleTimeout_Zero_DoesNotExpire()
10271028
var pool = ConstructPoolWithIdleTimeout(idleTimeoutSeconds: 0);
10281029
SqlConnection owner = new();
10291030
pool.TryGetConnection(owner, taskCompletionSource: null,
1031+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10301032
out DbConnectionInternal? first);
10311033
Assert.NotNull(first);
10321034

@@ -1037,6 +1039,7 @@ public void IdleTimeout_Zero_DoesNotExpire()
10371039
// Act
10381040
SqlConnection owner2 = new();
10391041
pool.TryGetConnection(owner2, taskCompletionSource: null,
1042+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10401043
out DbConnectionInternal? second);
10411044

10421045
// Assert - same instance, idle expiry disabled
@@ -1054,6 +1057,7 @@ public void IdleTimeout_Set_ExpiresOldConnection()
10541057
var pool = ConstructPoolWithIdleTimeout(idleTimeoutSeconds: 1);
10551058
SqlConnection owner = new();
10561059
pool.TryGetConnection(owner, taskCompletionSource: null,
1060+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10571061
out DbConnectionInternal? first);
10581062
Assert.NotNull(first);
10591063

@@ -1064,6 +1068,7 @@ public void IdleTimeout_Set_ExpiresOldConnection()
10641068
// Act - request another connection
10651069
SqlConnection owner2 = new();
10661070
pool.TryGetConnection(owner2, taskCompletionSource: null,
1071+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10671072
out DbConnectionInternal? second);
10681073

10691074
// Assert - the expired one is discarded; a new one is minted.
@@ -1082,13 +1087,15 @@ public void IdleTimeout_Set_KeepsFreshConnection()
10821087
var pool = ConstructPoolWithIdleTimeout(idleTimeoutSeconds: 60);
10831088
SqlConnection owner = new();
10841089
pool.TryGetConnection(owner, taskCompletionSource: null,
1090+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10851091
out DbConnectionInternal? first);
10861092
Assert.NotNull(first);
10871093
pool.ReturnInternalConnection(first, owner);
10881094

10891095
// Act - immediately request another connection
10901096
SqlConnection owner2 = new();
10911097
pool.TryGetConnection(owner2, taskCompletionSource: null,
1098+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
10921099
out DbConnectionInternal? second);
10931100

10941101
// Assert - same instance reused, well within idle window
@@ -1323,7 +1330,8 @@ public async Task ConcurrentCallers_ShouldTimeoutIndependently()
13231330
maxPoolSize: 1,
13241331
creationTimeout: 15,
13251332
loadBalanceTimeout: 0,
1326-
hasTransactionAffinity: true
1333+
hasTransactionAffinity: true,
1334+
idleTimeout: 0
13271335
);
13281336
var pool = ConstructPool(SuccessfulConnectionFactory, poolGroupOptions: poolGroupOptions);
13291337

src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/WaitHandleDbConnectionPoolIdleTimeoutTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private DbConnectionInternal GetConnection(SqlConnection owner)
6161
_pool.TryGetConnection(
6262
owner,
6363
taskCompletionSource: null,
64+
TimeoutTimer.StartNew(TimeSpan.FromSeconds(15)),
6465
out DbConnectionInternal? connection);
6566
Assert.NotNull(connection);
6667
return connection!;

0 commit comments

Comments
 (0)