def test_update_progress(datadir, tmpdir): bw_lines_raw = [] number_consensus_relays = 6 state = {} header = V3BWHeader(str(now_unixts())) results = load_result_file(str(datadir.join("results_away.txt"))) for fp, values in results.items(): # log.debug("Relay fp %s", fp) line = V3BWLine.from_results(values) if line is not None: bw_lines_raw.append(line) bwfile = V3BWFile(header, []) bwfile.update_progress(len(bw_lines_raw), header, number_consensus_relays, state) assert header.percent_eligible_relays == '50' assert state.get('min_perc_reached') is None # Test that the headers are also included when there are enough eligible # relays number_consensus_relays = 3 header = V3BWHeader(str(now_unixts())) bwfile.update_progress(len(bw_lines_raw), header, number_consensus_relays, state) assert state.get('min_perc_reached') == now_isodt_str() assert header.minimum_number_eligible_relays == '2' assert header.minimum_percent_eligible_relays == str(MIN_REPORT) assert header.number_consensus_relays == '3' assert header.number_eligible_relays == '3' assert header.percent_eligible_relays == '100'
def test_from_results_read(datadir, tmpdir, conf, args): results = load_result_file(str(datadir.join("results.txt"))) expected_header = V3BWHeader(timestamp_l, earliest_bandwidth=earliest_bandwidth, latest_bandwidth=latest_bandwidth) expected_bwls = [V3BWLine.from_results(results[fp]) for fp in results] # bw store now B, not KB expected_bwls[0].bw = round(expected_bwls[0].bw / 1000) expected_f = V3BWFile(expected_header, expected_bwls) # This way is going to convert bw to KB v3bwfile = V3BWFile.from_results(results) assert str(expected_f)[1:] == str(v3bwfile)[1:] output = os.path.join(args.output, now_fname()) v3bwfile.write(output)
def test_from_results_read(datadir, tmpdir, conf, args): results = load_result_file(str(datadir.join("results.txt"))) expected_header = V3BWHeader(timestamp_l, earliest_bandwidth=earliest_bandwidth, latest_bandwidth=latest_bandwidth) exclusion_dict = dict([ (k, 0) for k in BW_HEADER_KEYVALUES_RECENT_MEASUREMENTS_EXCLUDED ]) expected_header.add_relays_excluded_counters(exclusion_dict) raw_bwls = [V3BWLine.from_results(results[fp])[0] for fp in results] # Scale BWLines using torflow method, since it's the default and BWLines # bandwidth is the raw bandwidth. expected_bwls = V3BWFile.bw_torflow_scale(raw_bwls) expected_f = V3BWFile(expected_header, expected_bwls) # This way is going to convert bw to KB v3bwfile = V3BWFile.from_results(results) assert str(expected_f)[1:] == str(v3bwfile)[1:] output = os.path.join(args.output, now_fname()) v3bwfile.write(output)