public void ReturnConnection_ExceedPoolSize_GetConnectionShouldBlockAndReturnPreviousConnection() { // Arrange var pool = new SapConnectionPool( ConnectionParameters, poolSize: 1, connectionFactory: _ => Mock.Of <ISapConnection>()); ISapConnection connection1 = pool.GetConnection(); // Act Task.Run(async() => { await Task.Delay(150); pool.ReturnConnection(connection1); }); var sw = new Stopwatch(); sw.Start(); ISapConnection connection2 = pool.GetConnection(); sw.Stop(); // Assert sw.ElapsedMilliseconds.Should().BeGreaterThan(100); connection2.Should().NotBeNull(); connection2.Should().Be(connection1); connection1.Dispose(); connection2.Dispose(); pool.Dispose(); }
public void Dispose_ShouldDisposeIdleConnections() { // Arrange var connectionMock = new Mock <ISapConnection>(); var pool = new SapConnectionPool(ConnectionParameters, connectionFactory: _ => connectionMock.Object); ISapConnection connection1 = pool.GetConnection(); ISapConnection connection2 = pool.GetConnection(); pool.ReturnConnection(connection1); pool.ReturnConnection(connection2); // Act pool.Dispose(); // Assert connectionMock.Verify(x => x.Dispose(), Times.Exactly(2)); }