Skip to content

Commit 6c32763

Browse files
committed
Catch an arithmetic error
1 parent d0dfa96 commit 6c32763

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

partitionmanager/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _plan_partitions_for_time_offsets(
8686
for (i, offset), is_final in partitionmanager.tools.iter_show_end(
8787
enumerate(time_offsets)
8888
):
89-
increase = [x * offset / RATE_UNIT for x in rate_of_change]
89+
increase = [x * (offset / RATE_UNIT) for x in rate_of_change]
9090
predicted_positions = [
9191
int(p + i) for p, i in zip(ordered_current_pos, increase)
9292
]

partitionmanager/bootstrap_test.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@
99
_suffix,
1010
_trigger_column_copies,
1111
_override_config_to_map_data,
12+
_plan_partitions_for_time_offsets,
1213
calculate_sql_alters_from_state_info,
1314
write_state_info,
1415
)
1516
from .cli import Config
16-
from .types import DatabaseCommand, Table, SqlInput
17+
from .types import (
18+
DatabaseCommand,
19+
Table,
20+
SqlInput,
21+
MaxValuePartition,
22+
ChangePlannedPartition,
23+
NewPlannedPartition,
24+
)
1725

1826

1927
class MockDatabase(DatabaseCommand):
@@ -251,3 +259,14 @@ def test_generate_sql_copy_commands(self):
251259
"\t\tWHERE `id` = NEW.`id`;",
252260
],
253261
)
262+
263+
def test_plan_partitions_for_time_offsets(self):
264+
parts = _plan_partitions_for_time_offsets(
265+
datetime(2021, 3, 3),
266+
[timedelta(days=60), timedelta(days=360)],
267+
[11943234],
268+
[16753227640],
269+
MaxValuePartition("p_assumed", count=1),
270+
)
271+
self.assertIsInstance(parts[0], ChangePlannedPartition)
272+
self.assertIsInstance(parts[1], NewPlannedPartition)

0 commit comments

Comments
 (0)