commit c02d9b1e5ab0df3aa8ef19b1dbff8c23332ba682 Author: juga0 juga@riseup.net Date: Sat Mar 21 18:21:03 2020 +0000
chg: v3bwfile: Count recent relay's monitoring numbers
using timestamps class. Also add one more result to the tests data and change the test accordingly. --- sbws/lib/v3bwfile.py | 43 ++++++++++++++++++++++------------------- tests/unit/lib/data/results.txt | 5 +++-- tests/unit/lib/test_v3bwfile.py | 26 +++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index ee9fd17..6465892 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -656,26 +656,29 @@ class V3BWLine(object): kwargs['master_key_ed25519'] = results[0].master_key_ed25519 kwargs['time'] = cls.last_time_from_results(results) kwargs.update(cls.result_types_from_results(results)) - consensuses_count = \ - [r.relay_in_recent_consensus_count for r in results - if getattr(r, 'relay_in_recent_consensus_count', None)] - if consensuses_count: - consensus_count = max(consensuses_count) - kwargs['relay_in_recent_consensus_count'] = str(consensus_count) - - measurements_attempts = \ - [r.relay_recent_measurement_attempt_count for r in results - if getattr(r, 'relay_recent_measurement_attempt_count', None)] - if measurements_attempts: - kwargs['relay_recent_measurement_attempt_count'] = \ - str(max(measurements_attempts)) - - relay_recent_priority_list_counts = \ - [r.relay_recent_priority_list_count for r in results - if getattr(r, 'relay_recent_priority_list_count', None)] - if relay_recent_priority_list_counts: - kwargs['relay_recent_priority_list_count'] = \ - str(max(relay_recent_priority_list_counts)) + + # If it has not the attribute, return list to be able to call len + # If it has the attribute, but it is None, return also list + kwargs['relay_in_recent_consensus_count'] = str( + max([ + len(getattr(r, 'relay_in_recent_consensus', []) or []) + for r in results + ]) + ) + + kwargs['relay_recent_priority_list_count'] = str( + max([ + len(getattr(r, 'relay_recent_priority_list', []) or []) + for r in results + ]) + ) + + kwargs['relay_recent_measurement_attempt_count'] = str( + max([ + len(getattr(r, 'relay_recent_measurement_attempt', []) or []) + for r in results + ]) + )
success_results = [r for r in results if isinstance(r, ResultSuccess)]
diff --git a/tests/unit/lib/data/results.txt b/tests/unit/lib/data/results.txt index 4a95b58..36df3d9 100644 --- a/tests/unit/lib/data/results.txt +++ b/tests/unit/lib/data/results.txt @@ -1,2 +1,3 @@ -{"version": 4, "time": 1523887747, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "success", "rtts": [0.4596822261810303, 0.44872617721557617, 0.4563450813293457, 0.44872212409973145, 0.4561030864715576, 0.4765200614929199, 0.4495084285736084, 0.45711588859558105, 0.45520496368408203, 0.4635589122772217], "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "downloads": [{"amount": 590009, "duration": 6.1014368534088135}, {"amount": 590009, "duration": 8.391342878341675}, {"amount": 321663, "duration": 7.064587831497192}, {"amount": 321663, "duration": 8.266003131866455}, {"amount": 321663, "duration": 5.779450178146362}], "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s", "relay_average_bandwidth": 1000000000, "relay_burst_bandwidth": 123456, "relay_observed_bandwidth": 524288, "consensus_ba ndwidth": 600000, "consensus_bandwidth_is_unmeasured": false, "relay_recent_measurement_attempt_count": 1, "relay_recent_priority_list_count": 3} -{"version": 4, "time": 1523974147, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "error-stream", "msg": "Something bad happened while measuring bandwidth", "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s", "relay_recent_measurement_attempt_count": 2, "relay_recent_priority_list_count": 3} +{"version": 4, "time": 1523974147, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "error-stream", "msg": "Something bad happened while measuring bandwidth", "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"} +{"version": 4, "time": 1523887747, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "success", "rtts": [0.4596822261810303, 0.44872617721557617, 0.4563450813293457, 0.44872212409973145, 0.4561030864715576, 0.4765200614929199, 0.4495084285736084, 0.45711588859558105, 0.45520496368408203, 0.4635589122772217], "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "downloads": [{"amount": 590009, "duration": 6.1014368534088135}, {"amount": 590009, "duration": 8.391342878341675}, {"amount": 321663, "duration": 7.064587831497192}, {"amount": 321663, "duration": 8.266003131866455}, {"amount": 321663, "duration": 5.779450178146362}], "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s", "relay_average_bandwidth": 1000000000, "relay_burst_bandwidth": 123456, "relay_observed_bandwidth": 524288, "consensus_ba ndwidth": 600000, "consensus_bandwidth_is_unmeasured": false, "relay_in_recent_consensus": ["2018-04-07T14:09:07", "2018-04-07T14:09:07", "2018-04-07T14:09:07"], "relay_recent_measurement_attempt": ["2018-04-07T14:09:07", "2018-04-07T14:09:07"], "relay_recent_priority_list": ["2018-04-07T14:09:07", "2018-04-07T14:09:07", "2018-04-07T14:09:07"]} +{"version": 4, "time": 1523974147, "circ": ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"], "type": "error-stream", "msg": "Something bad happened while measuring bandwidth", "fingerprint": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "scanner": "IDidntEditTheSBWSConfig", "dest_url": "http://y.z", "nickname": "A", "address": "111.111.111.111", "master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s", "relay_in_recent_consensus": ["2018-04-07T14:09:07", "2018-04-07T14:09:07", "2018-04-07T14:09:07"], "relay_recent_measurement_attempt": ["2018-04-07T14:09:07", "2018-04-07T14:09:07"], "relay_recent_priority_list": ["2018-04-07T14:09:07", "2018-04-07T14:09:07", "2018-04-07T14:09:07"]} diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py index 7d26b8d..1028370 100644 --- a/tests/unit/lib/test_v3bwfile.py +++ b/tests/unit/lib/test_v3bwfile.py @@ -69,12 +69,13 @@ raw_bwl_str = "bw=56 bw_mean=61423 bw_median=55656 "\ "consensus_bandwidth=600000 consensus_bandwidth_is_unmeasured=False "\ "desc_bw_avg=1000000000 desc_bw_bur=123456 desc_bw_obs_last=524288 "\ "desc_bw_obs_mean=524288 error_circ=0 error_destination=0 error_misc=0 " \ - "error_second_relay=0 error_stream=1 " \ + "error_second_relay=0 error_stream=2 " \ "master_key_ed25519=g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s " \ "nick=A " \ "node_id=$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "\ + "relay_in_recent_consensus_count=3 "\ "relay_recent_measurement_attempt_count=2 "\ - "relay_recent_measurements_excluded_error_count=1 "\ + "relay_recent_measurements_excluded_error_count=2 "\ "relay_recent_priority_list_count=3 "\ "rtt=456 success=1 " \ "time=2018-04-17T14:09:07\n" @@ -571,3 +572,24 @@ def test_recent_priority_relay_count(root_data_path, datadir): results = load_result_file(str(datadir.join("results.txt"))) header = V3BWHeader.from_results(results, '', '', state_fpath) assert "15" == header.recent_priority_relay_count + + +def test_relay_recent_measurement_attempt_count(root_data_path, datadir): + results = load_result_file(str(datadir.join("results.txt"))) + for fp, values in results.items(): + line = V3BWLine.from_results(values) + assert "2" == line[0].relay_recent_measurement_attempt_count + + +def test_relay_recent_priority_list_count(root_data_path, datadir): + results = load_result_file(str(datadir.join("results.txt"))) + for fp, values in results.items(): + line = V3BWLine.from_results(values) + assert "3" == line[0].relay_recent_priority_list_count + + +def test_relay_in_recent_consensus_count(root_data_path, datadir): + results = load_result_file(str(datadir.join("results.txt"))) + for fp, values in results.items(): + line = V3BWLine.from_results(values) + assert "3" == line[0].relay_in_recent_consensus_count
tor-commits@lists.torproject.org