Skip to content

Commit

Permalink
Fix shard issue (#175)
Browse files Browse the repository at this point in the history
(DIS-3251)
  • Loading branch information
cecinestpasunepipe authored Jul 1, 2024
1 parent 54ecef7 commit f5b50b6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions acquire/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,7 @@ def acquire_children_and_targets(target: Target, args: argparse.Namespace) -> No
if (args.children and not args.skip_parent) or not args.children:
total_targets += 1
counter += 1
acquire_gui.shard = (progress_limit // total_targets) * counter
acquire_gui.shard = int((progress_limit / total_targets) * counter)
try:
files.extend(acquire_target(target, args, args.start_time))

Expand All @@ -2180,7 +2180,7 @@ def acquire_children_and_targets(target: Target, args: argparse.Namespace) -> No
if args.children:
for child in target.list_children():
counter += 1
acquire_gui.shard = (100 // total_targets) * counter
acquire_gui.shard = int((progress_limit / total_targets) * counter)
try:
child_target = load_child(target, child.path)
except Exception:
Expand Down
48 changes: 48 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from argparse import Namespace
from unittest.mock import MagicMock, patch

import pytest
from dissect.target import Target

from acquire.acquire import acquire_children_and_targets
from acquire.gui import GUI


@pytest.mark.parametrize(
"num_children, skip_parent, auto_upload, expected_shards",
[
(0, False, False, [90]), # 90 (default, leaves 10% for final 'step')
(0, False, True, [50]), # 50% till upload (upload progresses in plugin)
(1, False, False, [45, 90]), # two children to 90%
(1, True, False, [90]), # without parent, it's just one target - so 90%
(1, False, True, [25, 50]), # two children to 50%
(1, True, True, [50]), # one till upload (50%)
(2, False, False, [30, 60, 90]), # two children + parent till 90%
(2, False, True, [16, 33, 50]), # two children + parent till 50%
(50, False, True, list(range(0, 51))), # Should not be zero filled...
],
)
@patch("acquire.gui.base.Stub", spec=True)
@patch("acquire.acquire.acquire_target", create=True)
def test_gui(
mock_target: Target, gui: GUI, num_children: int, skip_parent: bool, auto_upload: bool, expected_shards: list[int]
):
def list_children() -> list[Target]:
yield from [mock_target] * num_children

mock_target.list_children = list_children

class Diagnostic_GUI(MagicMock):
@property
def shard(self) -> int:
return 0

@shard.setter
def shard(self, shard: int) -> None:
shards.append(shard)

GUI.__new__ = lambda x: Diagnostic_GUI()
shards = []
args = Namespace(child=False, auto_upload=auto_upload, children=True, skip_parent=skip_parent, start_time=0)
acquire_children_and_targets(mock_target, args)
assert shards == expected_shards

0 comments on commit f5b50b6

Please sign in to comment.