Skip to content

Commit

Permalink
Fix issue with fetching test-mode -1k document corpora. (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
drawlerr authored Feb 3, 2020
1 parent 39e9015 commit 1505223
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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

0 comments on commit 1505223

Please sign in to comment.