diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py')
-rw-r--r-- | src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py b/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py new file mode 100644 index 000000000..d96671360 --- /dev/null +++ b/src/pybind/mgr/pg_autoscaler/tests/test_cal_ratio.py @@ -0,0 +1,37 @@ +from pg_autoscaler import effective_target_ratio +from pytest import approx + + +def check_simple_ratio(target_ratio, tot_ratio): + etr = effective_target_ratio(target_ratio, tot_ratio, 0, 0) + assert (target_ratio / tot_ratio) == approx(etr) + return etr + + +def test_simple(): + etr1 = check_simple_ratio(0.2, 0.9) + etr2 = check_simple_ratio(2, 9) + etr3 = check_simple_ratio(20, 90) + assert etr1 == approx(etr2) + assert etr1 == approx(etr3) + + etr = check_simple_ratio(0.9, 0.9) + assert etr == approx(1.0) + etr1 = check_simple_ratio(1, 2) + etr2 = check_simple_ratio(0.5, 1.0) + assert etr1 == approx(etr2) + + +def test_total_bytes(): + etr = effective_target_ratio(1, 10, 5, 10) + assert etr == approx(0.05) + etr = effective_target_ratio(0.1, 1, 5, 10) + assert etr == approx(0.05) + etr = effective_target_ratio(1, 1, 5, 10) + assert etr == approx(0.5) + etr = effective_target_ratio(1, 1, 0, 10) + assert etr == approx(1.0) + etr = effective_target_ratio(0, 1, 5, 10) + assert etr == approx(0.0) + etr = effective_target_ratio(1, 1, 10, 10) + assert etr == approx(0.0) |