public void ForgetConnection_ExceedPoolSize_GetConnectionShouldBlockAndReturnNewConnection() { // 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.ForgetConnection(connection1); }); var sw = new Stopwatch(); sw.Start(); ISapConnection connection2 = pool.GetConnection(); sw.Stop(); // Assert sw.ElapsedMilliseconds.Should().BeGreaterThan(100); connection2.Should().NotBeNull(); connection2.Should().NotBe(connection1); }
public void ForgetConnection_ShouldDisposeConnection() { // Arrange var connectionMock = new Mock <ISapConnection>(); var pool = new SapConnectionPool(ConnectionParameters, connectionFactory: _ => connectionMock.Object); ISapConnection connection = pool.GetConnection(); // Act pool.ForgetConnection(connection); // Assert connectionMock.Verify(x => x.Dispose(), Times.Once); }
public void GetConnection_AfterForgetConnection_ShouldReturnDifferentConnection() { // Arrange var pool = new SapConnectionPool( ConnectionParameters, poolSize: 3, connectionFactory: _ => Mock.Of <ISapConnection>()); // Act ISapConnection connection1 = pool.GetConnection(); pool.ForgetConnection(connection1); ISapConnection connection2 = pool.GetConnection(); // Assert connection1.Should().NotBeNull(); connection2.Should().NotBeNull(); connection2.Should().NotBe(connection1); }