-
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.
Merge pull request #478 from reef-technologies/fix_upload_threads
allow set_thread_pool_size to be set after pool has been once used already
- Loading branch information
Showing
5 changed files
with
146 additions
and
45 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
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 @@ | ||
Add `set_thread_pool_size`, `get_thread_pool_size` to *Manger classes. |
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