コード例 #1
0
def test_throttler_init_invalid_args():
    for windowSize in (None, '5', [4]):
        with pytest.raises(PlenumTypeError):
            Throttler(windowSize)

    for windowSize in (-1, 0):
        with pytest.raises(PlenumValueError):
            Throttler(windowSize)
コード例 #2
0
ファイル: test_throttler.py プロジェクト: evernym/plenum
def test_throttler_case2():
    """
    Tests throttler with custom delay function
    """
    windowSize = 10
    testIterations = windowSize - 2
    ratchet = Ratchet(a=2, b=0.05, c=1, base=2, peak=windowSize)
    throttler = Throttler(windowSize, ratchet.get)
    cooldowns = [time.sleep(1) or throttler.acquire()[1] for i in range(testIterations)]
    middle = len(cooldowns) // 2
    firstIteration, secondIteration = cooldowns[:middle], cooldowns[middle:]
    for a, b in zip(firstIteration, secondIteration):
        if not a == b == 0:
            assert b > a
コード例 #3
0
def test_throttler_case1():
    '''
    Tests throttler with default delay function
    '''
    windowSize = 3
    throttler = Throttler(windowSize)
    testIterations = windowSize * 5
    for i in range(testIterations):
        hasAcquired, timeToWait = throttler.acquire()
        if i % windowSize == 0:
            assert hasAcquired
            assert round(timeToWait) == 0
        else:
            assert not hasAcquired
            assert windowSize - i % windowSize == round(timeToWait)
        time.sleep(1)
コード例 #4
0
def test_throttler_case2():
    '''
    Tests throttler with custom delay function
    '''
    windowSize = 10
    testIterations = windowSize - 2
    ratchet = Ratchet(a=2, b=0.05, c=1, base=2, peak=windowSize)
    throttler = Throttler(windowSize, ratchet.get)
    cooldowns = [
        time.sleep(1) or throttler.acquire()[1] for i in range(testIterations)
    ]
    middle = len(cooldowns) // 2
    firstIteration, secondIteration = cooldowns[:middle], cooldowns[middle:]
    for a, b in zip(firstIteration, secondIteration):
        if not a == b == 0:
            assert b > a
コード例 #5
0
ファイル: test_throttler.py プロジェクト: evernym/plenum
def test_throttler_case1():
    """
    Tests throttler with default delay function
    """
    windowSize = 3
    throttler = Throttler(windowSize)
    testIterations = windowSize * 5
    for i in range(testIterations):
        hasAcquired, timeToWait = throttler.acquire()
        if i % windowSize == 0:
            assert hasAcquired
            assert round(timeToWait) == 0
        else:
            assert not hasAcquired
            assert windowSize - i % windowSize == round(timeToWait)
        time.sleep(1)
コード例 #6
0
 def initInsChngThrottling(self):
     windowSize = self.node.config.ViewChangeWindowSize
     ratchet = Ratchet(a=2, b=0.05, c=1, base=2, peak=windowSize)
     self.insChngThrottler = Throttler(windowSize, ratchet.get)