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

[tor-commits] [sbws/maint-1.1] fix: test: Check that log prints a number



commit 3efb686765812146b7d861e38412c37b2b0e7190
Author: juga0 <juga@xxxxxxxxxx>
Date:   Mon Mar 23 09:21:50 2020 +0000

    fix: test: Check that log prints a number
    
    and not a list of timestamps.
---
 sbws/lib/heartbeat.py            | 2 +-
 tests/unit/lib/test_heartbeat.py | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/sbws/lib/heartbeat.py b/sbws/lib/heartbeat.py
index b7b2387..1236890 100644
--- a/sbws/lib/heartbeat.py
+++ b/sbws/lib/heartbeat.py
@@ -45,7 +45,7 @@ class Heartbeat(object):
         Log the percentage, the number of relays measured and not measured,
         the number of loops and the time elapsed since it started measuring.
         """
-        loops_count = self.state_dict.get('recent_priority_list_count', 0)
+        loops_count = self.state_dict.count('recent_priority_list')
 
         not_measured_fp_set = self.consensus_fp_set.difference(
             self.measured_fp_set
diff --git a/tests/unit/lib/test_heartbeat.py b/tests/unit/lib/test_heartbeat.py
index f3d8f52..b2ad634 100644
--- a/tests/unit/lib/test_heartbeat.py
+++ b/tests/unit/lib/test_heartbeat.py
@@ -2,9 +2,12 @@
 import logging
 
 from sbws.lib import heartbeat
+from sbws.util.state import State
 
 
 def test_total_measured_percent(conf, caplog):
+    state = State(conf["paths"]["state_fname"])
+    state["recent_priority_list"] = [1, 2, 3]
     hbeat = heartbeat.Heartbeat(conf.getpath('paths', 'state_fname'))
 
     hbeat.register_consensus_fprs(['A', 'B', 'C'])
@@ -19,6 +22,7 @@ def test_total_measured_percent(conf, caplog):
     hbeat.print_heartbeat_message()
 
     assert hbeat.previous_measurement_percent == 67
+    assert 0 == caplog.records[0].getMessage().find("Run 3 main loops.")
     assert 0 == caplog.records[1].getMessage().find(
         "Measured in total 2 (67%)"
     )



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