Skip to content

Commit

Permalink
fix upload threads setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Feb 24, 2024
1 parent 2e2bf6e commit 1377608
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ def _set_threads_from_args(self, args):
# FIXME: This is using deprecated API. It should be be replaced when moving to b2sdk apiver 3.
# There is `max_download_workers` param in B2Api constructor for this.
self.api.services.download_manager.set_thread_pool_size(threads)
self.api.services.upload_manager.set_thread_pool_size(threads)


class _TqdmCloser:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+upload_threads.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `--threads` option being silently ignored in upload commands.
30 changes: 30 additions & 0 deletions test/unit/console_tool/test_upload_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,33 @@ def test_upload_file__stdin(b2_cli, bucket, tmpdir, mock_stdin):
remove_version=True,
expected_part_of_stdout=expected_stdout,
)


def test_upload_file__threads_setting(b2_cli, bucket, tmp_path):
"""Test upload_file supports setting number of threads"""
filename = 'file1.txt'
content = 'hello world'
local_file1 = tmp_path / 'file1.txt'
local_file1.write_text(content)

expected_json = {
"action": "upload",
"contentSha1": "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
"fileInfo": {
"src_last_modified_millis": f"{local_file1.stat().st_mtime_ns // 1000000}"
},
"fileName": filename,
"size": len(content),
}
b2_cli.run(
[
'upload-file', '--noProgress', 'my-bucket', '--threads', '66',
str(local_file1), 'file1.txt'
],
expected_json_in_stdout=expected_json,
remove_version=True,
)

# b2sdk does not expose the thread pool size, so this test is very much expected to be changed when
# the internal implementation of the upload manager changes
assert b2_cli.b2_api.services.upload_manager._thread_pool._max_workers == 66

0 comments on commit 1377608

Please sign in to comment.