-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix typing on thread_pool and add tests
- Loading branch information
1 parent
2c7ce95
commit ed48c42
Showing
3 changed files
with
78 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
###################################################################### | ||
# | ||
# 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.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters