Skip to content

Commit

Permalink
fix calculate optimal part size bug
Browse files Browse the repository at this point in the history
for some situations(for example, use future package), math.ceil will return an integer for python2.x,
it will cause errors for calculate optimal part size for multipart uploads. So, add __future__ module
to make sure the integer division return a float.
  • Loading branch information
liuzxc committed Jan 8, 2018
1 parent 056aee7 commit 04a1901
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions minio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"""

from __future__ import absolute_import
# if math.ceil returns an integer and devide two integers returns a float, calculate
# part size will cause errors, so make sure division integers returns a float.
from __future__ import division
import io

import collections
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/optimal_part_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,27 @@
from nose.tools import eq_, raises
from unittest import TestCase

from minio.helpers import optimal_part_info
from minio.helpers import optimal_part_info, MAX_MULTIPART_OBJECT_SIZE
from minio.error import InvalidArgumentError

class TraceTest(TestCase):
@raises(InvalidArgumentError)
def test_input_size_wrong(self):
optimal_part_info(5000000000000000000)
optimal_part_info(MAX_MULTIPART_OBJECT_SIZE + 1)

def test_input_size_valid_maximum(self):
total_parts_count, part_size, last_part_size = optimal_part_info(5497558138880)
total_parts_count, part_size, last_part_size = optimal_part_info(MAX_MULTIPART_OBJECT_SIZE)
eq_(total_parts_count, 9987)
eq_(part_size, 550502400)
eq_(last_part_size, 241172480)

def test_input_size_valid(self):
total_parts_count, part_size, last_part_size = optimal_part_info(MAX_MULTIPART_OBJECT_SIZE/1024)
eq_(total_parts_count, 1229)
eq_(part_size, 5242880)
eq_(last_part_size, 4194304)

def test_input_size_is_special_value(self):
total_parts_count, part_size, last_part_size = optimal_part_info(-1)
eq_(total_parts_count, 9987)
eq_(part_size, 550502400)
Expand Down

0 comments on commit 04a1901

Please sign in to comment.