Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize values to avoid overflow issues with the remanence widget progress bar #5768

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5759.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix progress bar issue for offline availability when the workspace contains more than 2GB of data
15 changes: 13 additions & 2 deletions parsec/core/gui/remanence_management_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
from parsec.core.logged_core import LoggedCore


def normalize_progress(value: int, total: int, maxi: int = 0x7FFFFFFF) -> tuple[int, int]:
if total <= maxi:
return value, total
assert total != 0
normalized_value = int(round(value * maxi / total))
return normalized_value, maxi


class RemanenceManagementWidget(QWidget, Ui_RemanenceManagementWidget):
def __init__(self, jobs_ctx: QtToTrioJobScheduler, core: LoggedCore, workspace_fs: WorkspaceFS):
super().__init__()
Expand Down Expand Up @@ -106,10 +114,13 @@ def _update_text(self) -> None:
format_value = "{} - {} / {} (%p%)".format(
title, get_filesize(info.local_and_remote_size), get_filesize(info.total_size)
)
current_size, total_size = normalize_progress(
info.local_and_remote_size, info.total_size
)
self.progress_bar.setFormat(format_value)
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(info.total_size)
self.progress_bar.setValue(info.local_and_remote_size)
self.progress_bar.setMaximum(total_size)
self.progress_bar.setValue(current_size)
# Congratulate when a download is finished
if (
self._download_started
Expand Down
18 changes: 17 additions & 1 deletion tests/core/gui/test_workspace_remanence.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) AGPL-3.0 2016-present Scille SAS

import pytest
from hypothesis import assume, given
from hypothesis.strategies import integers
from PyQt5 import QtCore

from parsec.api.data import EntryName
from parsec.core.gui.lang import translate
from parsec.core.gui.remanence_management_widget import RemanenceManagementWidget
from parsec.core.gui.remanence_management_widget import (
RemanenceManagementWidget,
normalize_progress,
)
from parsec.core.gui.workspace_button import WorkspaceButton


Expand Down Expand Up @@ -183,3 +188,14 @@ def _wait_remanence_turned_on():
]

await aqtbot.wait_until(_wait_remanence_turned_on)


@given(integers(min_value=0), integers(min_value=1))
def test_normalize_progress(value, total):
assume(value <= total)
normalized_value, normalized_total = normalize_progress(value, total)
if total <= 0x7FFFFFFF:
assert value == normalized_value
assert total == normalized_total
precision = 5
assert round(value / total, precision) == round(normalized_value / normalized_total, precision)