コード例 #1
0
    def test_drop_expired_connections(self):
        mock_factory = Mock()

        mock_conn1 = Mock()
        mock_conn2 = Mock()
        mock_conn3 = Mock()

        mock_conn1.is_expired.return_value = True
        mock_conn2.is_expired.return_value = False
        mock_conn3.is_expired.return_value = True

        mock_factory.side_effect = [mock_conn1, mock_conn2, mock_conn3]
        pool = Pool(mock_factory, initial_connections=3)

        pool.drop_expired()

        ok_(mock_conn1 not in pool._pool)
        mock_conn1.close.assert_called_once_with()
        ok_(mock_conn2 in pool._pool)
        ok_(mock_conn3 not in pool._pool)
        mock_conn1.close.assert_called_once_with()