Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with fetching test-mode -1k document corpora. #885

Merged
merged 3 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions esrally/utils/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ def __init__(self, msg, accuracy=0):

def __call__(self, bytes_read, bytes_total):
from esrally.utils import convert
completed = bytes_read / bytes_total
total_as_mb = convert.bytes_to_human_string(bytes_total)
self.p.print("%s (%s total size)" % (self.msg, total_as_mb), self.percent_format % (completed * 100))
if bytes_total:
completed = bytes_read / bytes_total
total_as_mb = convert.bytes_to_human_string(bytes_total)
self.p.print("%s (%s total size)" % (self.msg, total_as_mb), self.percent_format % (completed * 100))
else:
self.p.print(self.msg, ".")

def finish(self):
self.p.finish()
Expand All @@ -82,10 +85,13 @@ def __call__(self, bytes_amount):
self._progress(self._bytes_read, self._expected_size_in_bytes)

s3 = boto3.resource("s3")
bucket = s3.Bucket(bucket_name)
if expected_size_in_bytes is None:
expected_size_in_bytes = bucket.Object(bucket_path).content_length
progress_callback = S3ProgressAdapter(expected_size_in_bytes, progress_indicator) if progress_indicator else None
s3.Bucket(bucket_name).download_file(bucket_path, local_path,
Callback=progress_callback,
Config=boto3.s3.transfer.TransferConfig(use_threads=False))
bucket.download_file(bucket_path, local_path,
Callback=progress_callback,
Config=boto3.s3.transfer.TransferConfig(use_threads=False))


def download_s3(url, local_path, expected_size_in_bytes=None, progress_indicator=None):
Expand Down
11 changes: 10 additions & 1 deletion tests/utils/net_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import random
import unittest.mock as mock
from unittest import TestCase
Expand All @@ -33,3 +32,13 @@ def test_download_from_s3_bucket(self, download):
expected_size, progress_indicator)
download.assert_called_once_with("mybucket.elasticsearch.org", "data/documents.json.bz2",
"/tmp/documents.json.bz2", expected_size, progress_indicator)

def test_progress(self):
progress = net.Progress("test")
mock_progress = mock.Mock()
progress.p = mock_progress
progress(42, 100)
assert mock_progress.print.called
mock_progress.reset_mock()
progress(42, None)
assert mock_progress.print.called