GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit fa1c0a4c authored by juga  's avatar juga 💬

fix: tests: Add tests loading results

in ResultDump and incrementing relay's monitoring KeyValues.
parent 5c45e321
......@@ -296,14 +296,6 @@ def end_event():
@pytest.fixture(scope='function')
def rd(args, conf, end_event):
def rd(args, conf_results):
from sbws.lib.resultdump import ResultDump
# in Travis the next line gives the error:
# TypeError: __init__() takes 3 positional arguments but 4 were given
# No idea why.
# Returning None to disable the test in case ResultDump can not be
# initialized.
try:
return ResultDump(args, conf, end_event)
except TypeError:
return None
return ResultDump(args, conf_results)
# -*- coding: utf-8 -*-
"""Unit tests for resultdump."""
from sbws.lib.resultdump import trim_results_ip_changed
import datetime
from sbws.lib.relaylist import Relay
from sbws.lib.resultdump import (
ResultError,
ResultErrorStream,
ResultSuccess,
trim_results_ip_changed,
load_result_file
)
def test_trim_results_ip_changed_defaults(resultdict_ip_not_changed):
......@@ -31,3 +41,57 @@ def test_trim_results_ip_changed_on_changed_ipv6(caplog,
assert record.levelname == 'WARNING'
assert 'Reseting bandwidth results when IPv6 changes, ' \
'is not yet implemented.\n' in caplog.text
def test_resultdump(
rd, args, conf_results, controller, router_status, server_descriptor
):
from sbws import settings
relay = Relay(
router_status.fingerprint,
controller,
ns=router_status,
desc=server_descriptor,
)
relay.increment_relay_recent_priority_list()
relay.increment_relay_recent_measurement_attempt()
r = ResultSuccess(
[], 2000, relay, ["A", "B"], "http://localhost/bw", "scanner_nick",
)
# Storing the result with `rd.queue.put` will not store the result to disk
# because the thread is not spawned with pytest.
rd.store_result(r)
results = rd.results_for_relay(relay)
# It has stored the result
assert 1 == len(results)
# The result has the correct attribute
assert 1 == len(results[0].relay_recent_priority_list)
# Store a second result for the sme relay
r = ResultError(
relay, ["A", "B"], "http://localhost/bw", "scanner_nick",
)
rd.store_result(r)
assert 2 == len(results)
assert 1 == len(results[1].relay_recent_priority_list)
settings.set_end_event()
def test_load(datadir):
results = load_result_file(str(datadir.join("results.txt")))
results = [v for values in results.values() for v in values]
r1 = results[1]
assert isinstance(r1, ResultSuccess)
assert isinstance(
r1.relay_recent_measurement_attempt[0], datetime.datetime
)
assert 2 == len(r1.relay_recent_measurement_attempt)
assert 3 == len(r1.relay_recent_priority_list)
assert 3 == len(r1.relay_in_recent_consensus)
r2 = results[2]
assert isinstance(r2, ResultErrorStream)
assert isinstance(
r2.relay_recent_measurement_attempt[0], datetime.datetime
)
assert 2 == len(r2.relay_recent_measurement_attempt)
assert 3 == len(r2.relay_recent_priority_list)
assert 3 == len(r2.relay_in_recent_consensus)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment