Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
fix: tests: Check the files generated in test net
Browse files Browse the repository at this point in the history
Test that the results, state and bandwidth file generated by running
the scanner and the generator in the the test network are correct.
  • Loading branch information
juga0 committed Mar 22, 2020
1 parent 0425b70 commit b4f12e4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 tes net tmp dir without initializing."""
os.makedirs(os.path.join(sbwshome_empty, 'datadir'), exist_ok=True)
return sbwshome_empty

Expand All @@ -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'] = {}
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/test_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
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

0 comments on commit b4f12e4

Please sign in to comment.