@@ -35,6 +35,19 @@ namespace Neo4j.Driver.Tests
35
35
{
36
36
public class ConnectionPoolTests
37
37
{
38
+ internal static ConnectionPool NewConnectionPoolWithNoConnectionTimeoutValidation (
39
+ IConnection connection ,
40
+ BlockingCollection < IPooledConnection > availableConnections = null ,
41
+ ConcurrentSet < IPooledConnection > inUseConnections = null )
42
+ {
43
+ var testConfigWithIdleTimeoutAndLifetimeCheckDisabled = new Config
44
+ {
45
+ MaxConnectionLifetime = Config . InfiniteInterval ,
46
+ ConnectionIdleTimeout = Config . InfiniteInterval
47
+ } ;
48
+ return new ConnectionPool ( connection , availableConnections , inUseConnections ,
49
+ poolSettings : new ConnectionPoolSettings ( testConfigWithIdleTimeoutAndLifetimeCheckDisabled ) ) ;
50
+ }
38
51
public class AcquireMethod
39
52
{
40
53
private readonly ITestOutputHelper _output ;
@@ -45,6 +58,17 @@ private IConnection MockedConnection
45
58
{
46
59
var mock = new Mock < IPooledConnection > ( ) ;
47
60
mock . Setup ( x => x . IsOpen ) . Returns ( true ) ;
61
+ mock . Setup ( x => x . IdleTimer ) . Returns ( MockedTimer ) ;
62
+ mock . Setup ( x => x . LifetimeTimer ) . Returns ( MockedTimer ) ;
63
+ return mock . Object ;
64
+ }
65
+ }
66
+
67
+ private ITimer MockedTimer
68
+ {
69
+ get {
70
+ var mock = new Mock < ITimer > ( ) ;
71
+ mock . Setup ( t => t . ElapsedMilliseconds ) . Returns ( 0 ) ;
48
72
return mock . Object ;
49
73
}
50
74
}
@@ -211,6 +235,8 @@ public void ShouldReuseWhenOpenConnectionInQueue()
211
235
var conns = new BlockingCollection < IPooledConnection > ( ) ;
212
236
var mock = new Mock < IPooledConnection > ( ) ;
213
237
mock . Setup ( x => x . IsOpen ) . Returns ( true ) ;
238
+ mock . Setup ( x => x . IdleTimer ) . Returns ( MockedTimer ) ;
239
+ mock . Setup ( x => x . LifetimeTimer ) . Returns ( MockedTimer ) ;
214
240
215
241
conns . Add ( mock . Object ) ;
216
242
var pool = new ConnectionPool ( MockedConnection , conns ) ;
@@ -237,7 +263,7 @@ public void ShouldReuseOpenConnectionWhenOpenAndClosedConnectionsInQueue()
237
263
238
264
conns . Add ( unhealthyMock . Object ) ;
239
265
conns . Add ( healthyMock . Object ) ;
240
- var pool = new ConnectionPool ( MockedConnection , conns ) ;
266
+ var pool = NewConnectionPoolWithNoConnectionTimeoutValidation ( MockedConnection , conns ) ;
241
267
242
268
pool . NumberOfAvailableConnections . Should ( ) . Be ( 2 ) ;
243
269
pool . NumberOfInUseConnections . Should ( ) . Be ( 0 ) ;
@@ -301,7 +327,11 @@ public void ShouldReuseIdleNotTooLongConn()
301
327
conns . Add ( mock . Object ) ;
302
328
var enableIdleTooLongTest = TimeSpan . FromMilliseconds ( 100 ) ;
303
329
var poolSettings = new ConnectionPoolSettings (
304
- new Config { MaxIdleConnectionPoolSize = 2 , ConnectionIdleTimeout = enableIdleTooLongTest } ) ;
330
+ new Config {
331
+ MaxIdleConnectionPoolSize = 2 ,
332
+ ConnectionIdleTimeout = enableIdleTooLongTest ,
333
+ MaxConnectionLifetime = Config . InfiniteInterval , // disable life time check
334
+ } ) ;
305
335
var pool = new ConnectionPool ( MockedConnection , conns , poolSettings : poolSettings ) ;
306
336
307
337
pool . NumberOfAvailableConnections . Should ( ) . Be ( 1 ) ;
@@ -343,7 +373,7 @@ public void ShouldAcquireNewWhenBeingUsedConcurrentlyBy(int numberOfThreads)
343
373
mockConns . Enqueue ( mock ) ;
344
374
}
345
375
346
- var pool = new ConnectionPool ( MockedConnection , conns ) ;
376
+ var pool = NewConnectionPoolWithNoConnectionTimeoutValidation ( MockedConnection , conns ) ;
347
377
348
378
pool . NumberOfAvailableConnections . Should ( ) . Be ( numberOfThreads ) ;
349
379
pool . NumberOfInUseConnections . Should ( ) . Be ( 0 ) ;
@@ -407,7 +437,7 @@ public void ShouldCloseAcquiredConnectionIfPoolDisposeStarted()
407
437
// Given
408
438
var conns = new BlockingCollection < IPooledConnection > ( ) ;
409
439
var healthyMock = new Mock < IPooledConnection > ( ) ;
410
- var pool = new ConnectionPool ( MockedConnection , conns ) ;
440
+ var pool = NewConnectionPoolWithNoConnectionTimeoutValidation ( MockedConnection , conns ) ;
411
441
412
442
pool . NumberOfAvailableConnections . Should ( ) . Be ( 0 ) ;
413
443
pool . NumberOfInUseConnections . Should ( ) . Be ( 0 ) ;
@@ -453,6 +483,7 @@ public void ShouldTimeoutAfterAcquireTimeoutIfPoolIsFull()
453
483
public void ShouldTimeoutAfterAcquireTimeoutWhenConnectionIsNotValidated ( )
454
484
{
455
485
Config config = Config . Builder . WithConnectionAcquisitionTimeout ( TimeSpan . FromSeconds ( 5 ) )
486
+ . WithConnectionTimeout ( Config . InfiniteInterval )
456
487
. ToConfig ( ) ;
457
488
458
489
var notValidConnection = new Mock < IPooledConnection > ( ) ;
0 commit comments