1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
######################################################################
#
# File: test/unit/utils/test_thread_pool.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from concurrent.futures import Future
import pytest
from b2sdk._internal.utils.thread_pool import LazyThreadPool
class TestLazyThreadPool:
@pytest.fixture
def thread_pool(self):
return LazyThreadPool()
def test_submit(self, thread_pool):
future = thread_pool.submit(sum, (1, 2))
assert isinstance(future, Future)
assert future.result() == 3
def test_set_size(self, thread_pool):
thread_pool.set_size(10)
assert thread_pool.get_size() == 10
def test_get_size(self, thread_pool):
assert thread_pool.get_size() > 0
def test_set_size__after_submit(self, thread_pool):
future = thread_pool.submit(sum, (1, 2))
thread_pool.set_size(7)
assert thread_pool.get_size() == 7
assert future.result() == 3
assert thread_pool.submit(sum, (1,)).result() == 1
|