]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/pg_autoscaler: add unit tests for effective_target_ratio 33035/head
authorJosh Durgin <jdurgin@redhat.com>
Sun, 2 Feb 2020 21:29:13 +0000 (16:29 -0500)
committerKefu Chai <kchai@redhat.com>
Mon, 10 Feb 2020 05:00:00 +0000 (13:00 +0800)
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
src/pybind/mgr/pg_autoscaler/__init__.py
src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py [new file with mode: 0644]
src/pybind/mgr/requirements.txt
src/pybind/mgr/tox.ini

index e7c7b8fc01bccdcf9e8d6699744b325d362dd354..f0bffcdcd6293dac56d7c8760f11b5d86fc5bb35 100644 (file)
@@ -1 +1 @@
-from .module import PgAutoscaler
+from .module import PgAutoscaler, effective_target_ratio
diff --git a/src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py b/src/pybind/mgr/pg_autoscaler/tests/test_autoscaler.py
new file mode 100644 (file)
index 0000000..122d952
--- /dev/null
@@ -0,0 +1,34 @@
+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)
index 21a5b35af45f2385c69b2d03232dfb7b4e8e637d..f14efb8cd80d5a6d216efed924d55f44ae5d056f 100644 (file)
@@ -4,4 +4,5 @@ ipaddress; python_version < '3.3'
 ../../python-common
 kubernetes
 requests-mock
-pyyaml
\ No newline at end of file
+pyyaml
+prettytable
index ac3424e87cb1e1ebbbd2c7edbbb62b6960552031..d9ea1ef5fd0575c43e3fab0b53f325a3bdd2c4a5 100644 (file)
@@ -5,7 +5,7 @@ skipsdist = true
 [testenv]
 setenv = UNITTEST = true
 deps = -r requirements.txt
-commands = pytest -v --cov --cov-append --cov-report=term --doctest-modules {posargs:mgr_util.py tests/ cephadm/ progress/}
+commands = pytest -v --cov --cov-append --cov-report=term --doctest-modules {posargs:mgr_util.py tests/ cephadm/ pg_autoscaler/ progress/}
 
 [testenv:mypy]
 basepython = python3