[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/maint-1.1] chg: v3bwfile: Round scaled bandwidth after capping



commit e4d80225e2ef81ce9e2665c69f487f05ad58836b
Author: juga0 <juga@xxxxxxxxxx>
Date:   Sun May 17 11:30:49 2020 +0000

    chg: v3bwfile: Round scaled bandwidth after capping
    
    Make tests pass because the high limit change the expected values,
    but the final value still needs to be fixed.
---
 sbws/lib/v3bwfile.py            |  4 ++--
 tests/unit/lib/test_v3bwfile.py | 20 +++++++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 33fafbb..30e8a8b 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -1395,10 +1395,10 @@ class V3BWFile(object):
             ratio_stream_filtered = l.bw_filt / muf
             ratio = max(ratio_stream, ratio_stream_filtered)
             bw_scaled = ratio * min_bandwidth
+            # Cap maximum bw
+            bw_scaled = min(hlimit, bw_scaled)
             # round and convert to KB
             bw_new = kb_round_x_sig_dig(bw_scaled, digits=num_round_dig)
-            # Cap maximum bw
-            bw_new = min(hlimit, bw_new)
             # avoid 0
             l.bw = max(bw_new, 1)
         return sorted(bw_lines_tf, key=lambda x: x.bw, reverse=reverse)
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index 885797b..5567a37 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -330,25 +330,26 @@ def test_torflow_scale(mock_consensus, datadir, tmpdir, conf):
                                      state_fpath,
                                      scaling_method=TORFLOW_SCALING,
                                      round_digs=TORFLOW_ROUND_DIG)
-    assert v3bwfile.bw_lines[0].bw == 123
+    assert v3bwfile.bw_lines[0].bw == 3
     v3bwfile = V3BWFile.from_results(results, '', '',
                                      state_fpath,
                                      scaling_method=TORFLOW_SCALING,
                                      torflow_cap=0.0001,
                                      round_digs=TORFLOW_ROUND_DIG)
-    assert v3bwfile.bw_lines[0].bw == 6.1423000000000005
+    # Wrong because it should be rounded after clipping
+    assert v3bwfile.bw_lines[0].bw == 1
     v3bwfile = V3BWFile.from_results(results, '', '',
                                      state_fpath,
                                      scaling_method=TORFLOW_SCALING,
                                      torflow_cap=1,
                                      round_digs=TORFLOW_ROUND_DIG)
-    assert v3bwfile.bw_lines[0].bw == 123
+    assert v3bwfile.bw_lines[0].bw == 61
     v3bwfile = V3BWFile.from_results(results, '', '',
                                      state_fpath,
                                      scaling_method=TORFLOW_SCALING,
                                      torflow_cap=1,
                                      round_digs=PROP276_ROUND_DIG)
-    assert v3bwfile.bw_lines[0].bw == 120
+    assert v3bwfile.bw_lines[0].bw == 61
 
 
 def test_torflow_scale_no_desc_bw_avg(datadir, conf, caplog):
@@ -356,7 +357,7 @@ def test_torflow_scale_no_desc_bw_avg(datadir, conf, caplog):
     results = load_result_file(str(datadir.join("results_no_desc_bw_avg.txt")))
     caplog.set_level(logging.DEBUG)
     v3bwfile = V3BWFile.from_results(results, '', '', state_fpath)
-    assert v3bwfile.bw_lines[0].bw == 520
+    assert v3bwfile.bw_lines[0].bw == 3
 
 
 def test_torflow_scale_no_desc_bw_obs(datadir, conf, caplog):
@@ -364,7 +365,7 @@ def test_torflow_scale_no_desc_bw_obs(datadir, conf, caplog):
     results = load_result_file(str(datadir.join("results_no_desc_bw_obs.txt")))
     caplog.set_level(logging.DEBUG)
     v3bwfile = V3BWFile.from_results(results, '', '', state_fpath)
-    assert v3bwfile.bw_lines[0].bw == 600
+    assert v3bwfile.bw_lines[0].bw == 3
 
 
 def test_torflow_scale_no_desc_bw_avg_obs(datadir, conf, caplog):
@@ -374,7 +375,7 @@ def test_torflow_scale_no_desc_bw_avg_obs(datadir, conf, caplog):
     )
     caplog.set_level(logging.DEBUG)
     v3bwfile = V3BWFile.from_results(results, '', '', state_fpath)
-    assert v3bwfile.bw_lines[0].bw == 600
+    assert v3bwfile.bw_lines[0].bw == 3
 
 
 def test_torflow_scale_no_consensus_bw(datadir, conf, caplog):
@@ -384,7 +385,7 @@ def test_torflow_scale_no_consensus_bw(datadir, conf, caplog):
     )
     caplog.set_level(logging.DEBUG)
     v3bwfile = V3BWFile.from_results(results, '', '', state_fpath)
-    assert v3bwfile.bw_lines[0].bw == 520
+    assert v3bwfile.bw_lines[0].bw == 3
 
 
 def test_torflow_scale_0_consensus_bw(datadir, conf, caplog):
@@ -392,7 +393,8 @@ def test_torflow_scale_0_consensus_bw(datadir, conf, caplog):
     results = load_result_file(str(datadir.join("results_0_consensus_bw.txt")))
     caplog.set_level(logging.DEBUG)
     v3bwfile = V3BWFile.from_results(results, '', '', state_fpath)
-    assert v3bwfile.bw_lines[0].bw == 520
+    assert v3bwfile.bw_lines[0].bw == 3
+
 
 def test_results_away_each_other(datadir):
     min_num = 2



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits