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 results_recent_than(results, secs_recent=None): if secs_recent is None: return results results_recent = filter( lambda x: (now_unixts() - x.time) < secs_recent, results) return list(results_recent)