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 4e2ccf3c authored by juga  's avatar juga 💬

fix: tests: Check the files generated in test net

Test that the results, state and bandwidth file generated by running
the scanner and the generator in the test network are correct.
parent fa1c0a4c
......@@ -36,15 +36,15 @@ def tmpdir(tmpdir_factory, request):
@pytest.fixture(scope='session')
def sbwshome_empty(tmpdir):
"""Create sbws home inside of the tests tmp dir without initializing."""
home = tmpdir.join('.sbws')
os.makedirs(home.strpath, exist_ok=True)
return home.strpath
"""Create sbws home inside of the test net tmp dir without initializing."""
home = "/tmp/.sbws"
os.makedirs(home, exist_ok=True)
return home
@pytest.fixture(scope='session')
def sbwshome_dir(sbwshome_empty):
"""Create sbws home inside of the tests tmp dir without initializing."""
"""Create sbws home inside of the test net tmp dir without initializing."""
os.makedirs(os.path.join(sbwshome_empty, 'datadir'), exist_ok=True)
return sbwshome_empty
......@@ -69,6 +69,7 @@ def conf(sbwshome_dir):
"""Default configuration with sbws home in the tmp test dir."""
conf = _get_default_config()
conf['paths']['sbws_home'] = sbwshome_dir
conf["paths"]["state_fpath"] = os.path.join(sbwshome_dir, "state.dat")
conf['tor']['run_dpath'] = os.path.join(sbwshome_dir, 'tor', 'run')
conf['destinations']['foo'] = 'on'
conf['destinations.foo'] = {}
......
"""
Integration tests for the files with data to be used by the bandwidth file.
"""
from sbws.lib.resultdump import load_recent_results_in_datadir
from sbws.lib.v3bwfile import V3BWFile
from sbws.util.state import State
def test_results(conf):
results = load_recent_results_in_datadir(5, conf["paths"]["datadir"])
for fp, values in results.items():
count = max(
[
len(getattr(r, "relay_recent_measurement_attempt", []))
for r in values
]
)
assert count == 1
count = max(
[len(getattr(r, "relay_in_recent_consensus", [])) for r in values]
)
assert count == 1
count = max(
[len(getattr(r, "relay_recent_priority_list", [])) for r in values]
)
assert count == 1
def test_state(conf):
state = State(conf["paths"]["state_fpath"])
assert 1 == state.count("recent_consensus")
assert 1 == state.count("recent_priority_list")
assert 15 == state.count("recent_priority_relay")
assert 15 == state.count("recent_measurement_attempt")
def test_v3bwfile(conf):
bwfile = V3BWFile.from_v1_fpath(
conf["paths"]["v3bw_fname"].format("latest")
)
assert "1" == bwfile.header.recent_consensus_count
assert "1" == bwfile.header.recent_priority_list_count
assert "15" == bwfile.header.recent_priority_relay_count
assert "15" == bwfile.header.recent_measurement_attempt_count
for bwline in bwfile.bw_lines:
assert 1 == bwline.relay_in_recent_consensus_count
assert 1 == bwline.relay_recent_priority_list_count
assert 1 == bwline.relay_recent_measurement_attempt_count
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