Beispiel #1
0
def test_run_with_shrink_value_calls_shrink_and_not_grow():
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10)
    resizer.run()
    assert not resizer.grow.called
    assert resizer.can_shrink.called
    resizer.shrink.assert_called_once_with(3)
Beispiel #2
0
def test_cannot_shrink_before_shrinkfreq():
    shrinkfreq = 3
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10,
                                 shrinkfreq=shrinkfreq)
    resizer.shrink(1)
    resizer.lastshrink -= (shrinkfreq - 1)
    assert resizer.can_shrink() is False
Beispiel #3
0
def get_pool_resizer(self,
                     minspare=1,
                     maxspare=5,
                     shrinkfreq=10,
                     logfreq=0,
                     logger=None):
    return DynamicPoolResizer(self, minspare, maxspare, shrinkfreq, logfreq,
                              logger)
Beispiel #4
0
def test_new_resizer_can_shrink():
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10)
    assert resizer.lastshrink is None
    assert resizer.can_shrink() is True
Beispiel #5
0
def test_shrink_sets_lastshrink():
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10)
    assert resizer.lastshrink is None
    resizer.shrink(10)
    assert resizer.lastshrink is not None
Beispiel #6
0
def test_shrink_calls_threadpool_shrink():
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10)
    resizer.shrink(10)
    pool.shrink.assert_called_once_with(10)
Beispiel #7
0
def test_grow_calls_threadpool_grow():
    pool = Mock()
    resizer = DynamicPoolResizer(pool, minspare=5, maxspare=10)
    resizer.grow(10)
    pool.grow.assert_called_once_with(10)