Skip to content

Commit

Permalink
πŸ› Fix flaky test_disk_usage (#5364)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Neagu <[email protected]>
  • Loading branch information
GitHK and Andrei Neagu authored Feb 23, 2024
1 parent 889e0ff commit f23a597
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import psutil
import pytest
from models_library.api_schemas_dynamic_sidecar.telemetry import DiskUsage
from psutil._common import sdiskusage


def test_disk_usage():
ps_util_disk_usage = psutil.disk_usage("/")
def _assert_same_value(ps_util_disk_usage: sdiskusage) -> None:
disk_usage = DiskUsage.from_ps_util_disk_usage(ps_util_disk_usage)
assert disk_usage.used == ps_util_disk_usage.used
assert disk_usage.free == ps_util_disk_usage.free
assert round(disk_usage.used_percent, 1) == round(ps_util_disk_usage.percent, 1)
assert disk_usage.used_percent == pytest.approx(ps_util_disk_usage.percent, abs=1e3)


@pytest.mark.parametrize(
"ps_util_disk_usage",
[
sdiskusage(total=77851254784, used=58336940032, free=19497537536, percent=74.9),
sdiskusage(total=77851254784, used=58573619200, free=19260858368, percent=75.3),
sdiskusage(total=77851254784, used=58573529088, free=19260948480, percent=75.3),
sdiskusage(total=77851254784, used=58573664256, free=19260813312, percent=75.3),
],
)
def test_disk_usage_regression_cases(ps_util_disk_usage: sdiskusage):
_assert_same_value(ps_util_disk_usage)


def test_disk_usage():
ps_util_disk_usage = psutil.disk_usage("/")
_assert_same_value(ps_util_disk_usage)

0 comments on commit f23a597

Please sign in to comment.