Ejemplo n.º 1
0
def test_thread_limiting_raises_mutex_args(kmsg, mocker, mock_config):
    limiter = _thread_limiter.ThreadLimiter(max_thread_count=1)

    with pytest.raises(RuntimeError):

        @decorators._handle_klio(max_thread_count=1, thread_limiter=limiter)
        def func(*args, **kwargs):
            pass

        func(kmsg.SerializeToString())
Ejemplo n.º 2
0
def test_thread_limiter_ctx_mgr(max_thread_count, mocker, monkeypatch, caplog):
    mock_semaphore = mocker.Mock()
    limiter = _thread_limiter.ThreadLimiter(max_thread_count=max_thread_count)
    monkeypatch.setattr(limiter, "_semaphore", mock_semaphore)

    with limiter:
        3 * 3

    mock_semaphore.acquire.assert_called_once_with()
    mock_semaphore.release.assert_called_once_with()
    assert 3 == len(caplog.messages)
Ejemplo n.º 3
0
def test_thread_limiting_custom_limiter(kmsg, mock_config, mocker,
                                        monkeypatch):
    mock_function = mocker.Mock()
    mock_semaphore = mocker.Mock()

    limiter = _thread_limiter.ThreadLimiter(max_thread_count=1)
    monkeypatch.setattr(limiter, "_semaphore", mock_semaphore)

    @decorators._handle_klio(thread_limiter=limiter)
    def func(*args, **kwargs):
        mock_function(*args, **kwargs)
        return

    func(kmsg.SerializeToString())

    assert 1 == mock_function.call_count
    mock_semaphore.acquire.assert_called_once_with()
    mock_semaphore.release.assert_called_once_with()
Ejemplo n.º 4
0
def test_thread_limiter(max_thread_count, exp_count_log, caplog):
    _thread_limiter.ThreadLimiter(max_thread_count=max_thread_count)

    assert 1 == len(caplog.messages)
    assert exp_count_log in caplog.messages[0]