Base the progress ETA on the last 30 seconds and show the copy speed
The whole-run file rate is dominated by hard-linked files, so after a big folder moved the ETA showed seconds while gigabytes were still to be copied.
This commit is contained in:
4 files changed
+127
-20
No files matched your search
+47
-15
@@ -263,10 +263,26 @@ def test_format_duration(seconds: float, text: str) -> None:
|
||||
assert sb._format_duration(seconds) == text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('size', 'size_bytes'), [
|
||||
('30,000,000B', 30_000_000), ('4,000,000', 4_000_000), ('30.0MB', 30_000_000), ('30,0MB', 30_000_000),
|
||||
('2.00M', 2_000_000), ('1.5GB', 1_500_000_000), ('28.6MiB', 29_989_273), ('512B', 512), ('?', None),
|
||||
('1.2.3MB', None),
|
||||
])
|
||||
def test_parse_size(size: str, size_bytes: int | None) -> None:
|
||||
assert sb._parse_size(size) == size_bytes
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('speed', 'text'), [
|
||||
(0, '0B/s'), (999, '999B/s'), (1500, '1.5KB/s'), (10_500_000, '10.5MB/s'), (2e9, '2.0GB/s'), (3e12, '3.0TB/s'),
|
||||
])
|
||||
def test_format_speed(speed: float, text: str) -> None:
|
||||
assert sb._format_speed(speed) == text
|
||||
|
||||
|
||||
class TestProgressBar:
|
||||
@pytest.fixture(autouse=True)
|
||||
def terminal(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((81, 24)))
|
||||
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
|
||||
# 30 s elapsed at each update
|
||||
monkeypatch.setattr(sb, 'default_timer', iter([0.0, 30.0]).__next__)
|
||||
|
||||
@@ -274,7 +290,7 @@ class TestProgressBar:
|
||||
bar = sb._ProgressBar()
|
||||
|
||||
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=1009/2632)')
|
||||
assert capsys.readouterr().err == '\r1,623 files checked 2.00M copied (scanning)\033[K'
|
||||
assert capsys.readouterr().err == '\r1,623 files checked 2.00M copied 66.7KB/s (scanning)\033[K'
|
||||
|
||||
def test_update(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar()
|
||||
@@ -282,7 +298,7 @@ class TestProgressBar:
|
||||
# With --link-dest rsync's percentage leaves out linked files, so the files are counted instead
|
||||
assert bar.update(' 4,000,000 1% 2.97MB/s 0:00:01 (xfr#2, to-chk=1/4)')
|
||||
assert capsys.readouterr().err == \
|
||||
'\r[######################--------] 75% 3/4 files 4,000,000 copied ETA 0:00:10\033[K'
|
||||
'\r[######################--------] 75% 3/4 files 4,000,000 copied 133.3KB/s ETA 0:00:10\033[K'
|
||||
|
||||
def test_keeps_counts_within_file(self, monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
@@ -291,43 +307,59 @@ class TestProgressBar:
|
||||
|
||||
assert bar.update(' 2.00M 1% 1.47MB/s 0:00:02 (xfr#1, to-chk=2/4)')
|
||||
assert bar.update(' 3.00M 2% 1.47MB/s 0:00:03')
|
||||
assert capsys.readouterr().err.endswith('] 50% 2/4 files 3.00M copied ETA 0:00:30\033[K')
|
||||
assert capsys.readouterr().err.endswith('] 50% 2/4 files 3.00M copied 100.0KB/s ETA 0:00:30\033[K')
|
||||
|
||||
def test_estimate_while_scanning(self, monkeypatch: pytest.MonkeyPatch,
|
||||
def test_eta_follows_recent_pace(self, monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
|
||||
monkeypatch.setattr(sb, 'default_timer', iter([0.0, 100.0, 130.0]).__next__)
|
||||
bar = sb._ProgressBar()
|
||||
|
||||
# Fast while linking unchanged files, then one file in the last 30 s
|
||||
assert bar.update(' 10.00M 1% 1.47MB/s 0:00:02 (xfr#1, to-chk=100/1000)')
|
||||
assert capsys.readouterr().err.endswith(' 100.0KB/s ETA 0:00:11\033[K')
|
||||
assert bar.update(' 70.00M 7% 1.47MB/s 0:00:02 (xfr#2, to-chk=99/1000)')
|
||||
assert capsys.readouterr().err.endswith(' 2.0MB/s ETA 0:49:30\033[K')
|
||||
|
||||
def test_eta_unknown_within_big_file(self, monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
monkeypatch.setattr(sb, 'default_timer', iter([0.0, 10.0, 50.0]).__next__)
|
||||
bar = sb._ProgressBar()
|
||||
|
||||
assert bar.update(' 10.00M 1% 1.47MB/s 0:00:02 (xfr#1, to-chk=10/20)')
|
||||
# No file finished in the last 30 s
|
||||
assert bar.update(' 50.00M 5% 1.47MB/s 0:00:02')
|
||||
assert capsys.readouterr().err.endswith(' 50.00M copied 1.0MB/s ETA --:--:--\033[K')
|
||||
|
||||
def test_estimate_while_scanning(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar(estimate=4000)
|
||||
|
||||
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=1000/2000)')
|
||||
assert bar.total is None
|
||||
assert capsys.readouterr().err == \
|
||||
'\r[#######-----------------------] ~25% 1,000/~4,000 files 2.00M copied ETA ~0:01:30\033[K'
|
||||
'\r[#######-----------------------] ~25% 1,000/~4,000 files 2.00M copied 66.7KB/s ETA ~0:01:30\033[K'
|
||||
|
||||
def test_estimate_exceeded(self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
|
||||
def test_estimate_exceeded(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar(estimate=1000)
|
||||
|
||||
# More files than in the last backup: estimate from the files found so far
|
||||
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=500/2000)')
|
||||
assert capsys.readouterr().err == \
|
||||
'\r[######################--------] ~75% 1,500/~2,000 files 2.00M copied ETA ~0:00:10\033[K'
|
||||
'\r[######################--------] ~75% 1,500/~2,000 files 2.00M copied 66.7KB/s ETA ~0:00:10\033[K'
|
||||
|
||||
def test_estimate_capped_while_scanning(self, monkeypatch: pytest.MonkeyPatch,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
|
||||
def test_estimate_capped_while_scanning(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar(estimate=1000)
|
||||
|
||||
# All files found so far are checked, but rsync may still find more
|
||||
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=0/2000)')
|
||||
assert bar.total is None
|
||||
assert ' ~99% 2,000/~2,000 files 2.00M copied ETA ~0:00:00\033[K' in capsys.readouterr().err
|
||||
assert ' ~99% 2,000/~2,000 files 2.00M copied 66.7KB/s ETA ~0:00:00\033[K' in capsys.readouterr().err
|
||||
|
||||
def test_no_estimate_without_last_count(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar()
|
||||
|
||||
# The files found so far are only a guess at the total near the end of the scan
|
||||
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=0/2000)')
|
||||
assert capsys.readouterr().err == '\r2,000 files checked 2.00M copied (scanning)\033[K'
|
||||
assert capsys.readouterr().err == '\r2,000 files checked 2.00M copied 66.7KB/s (scanning)\033[K'
|
||||
|
||||
def test_real_total_replaces_estimate(self, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
bar = sb._ProgressBar(estimate=4000)
|
||||
|
||||
Reference in new issue
Block a user