Commit 7a159324 authored by Matt Traudt's avatar Matt Traudt Committed by Matt Traudt
Browse files

Add integration tests, reorg tests

parent 636eead7
......@@ -83,6 +83,18 @@ def init_controller(port=None, path=None, set_custom_stream_settings=True):
return c, ''
def is_bootstrapped(c):
if not is_controller_okay(c):
return False
line = c.get_info('status/bootstrap-phase')
state, _, progress, *_ = line.split()
progress = int(progress.split('=')[1])
if state == 'NOTICE' and progress == 100:
return True
log.debug('Not bootstrapped. state={} progress={}'.format(state, progress))
return False
def is_controller_okay(c):
if not c:
return False
......
import pytest
from tempfile import TemporaryDirectory
from sbws.util.parser import create_parser
from sbws.util.config import get_config
from sbws.util.stem import launch_tor
import sbws.core.init
@pytest.fixture(scope='session')
def parser():
return create_parser()
@pytest.fixture(scope='session')
def persistent_empty_dotsbws(parser):
'''
Creates a ~/.sbws with nothing in it but a config.ini
'''
d = TemporaryDirectory()
args = parser.parse_args(
'-d {} --log-level DEBUG init'.format(d.name).split())
conf = get_config(args)
sbws.core.init.main(args, conf)
return d
@pytest.fixture(scope='session')
def persistent_launch_tor(parser, persistent_empty_dotsbws):
d = persistent_empty_dotsbws
args = parser.parse_args('-d {}'.format(d.name).split())
conf = get_config(args)
conf['tor']['extra_lines'] = '''
DirAuthority auth1 orport=2002 no-v2 v3ident=D7DBC517EFD2BA1A5012CF1BD0BB38F17C8160BD 127.10.0.1:2003 AA45C13025C037F056E734169891878ED0880231
DirAuthority auth2 orport=2002 no-v2 v3ident=4EE103A081F400E6622F5461D51782B876BB5C24 127.10.0.2:2003 E7B3C9A0040D628DAC88B0251AE6334D28E8F531
DirAuthority auth3 orport=2002 no-v2 v3ident=8B85069C7FC0593801E6491A34100264FCE28980 127.10.0.3:2003 35E3B8BB71C81355649AEC5862ECB7ED7EFDBC5C
TestingTorNetwork 1
NumCPUs 1
LogTimeGranularity 1
SafeLogging 0
'''
cont = launch_tor(conf)
return cont
import sbws.util.stem as stem_utils
from stem.descriptor.router_status_entry import RouterStatusEntryV3
def test_foo(persistent_launch_tor):
cont = persistent_launch_tor
assert stem_utils.is_controller_okay(cont)
assert stem_utils.is_bootstrapped(cont)
def test_get_relay_from_fp(persistent_launch_tor):
cont = persistent_launch_tor
# AA45C13025C037F056E734169891878ED0880231 is auth1
relay = stem_utils.fp_or_nick_to_relay(
cont, 'AA45C13025C037F056E734169891878ED0880231')
assert isinstance(relay, RouterStatusEntryV3)
assert relay.fingerprint == 'AA45C13025C037F056E734169891878ED0880231'
assert relay.nickname == 'auth1'
def test_get_relay_from_nick(persistent_launch_tor):
cont = persistent_launch_tor
# AA45C13025C037F056E734169891878ED0880231 is auth1
relay = stem_utils.fp_or_nick_to_relay(cont, 'auth1')
assert isinstance(relay, RouterStatusEntryV3)
assert relay.fingerprint == 'AA45C13025C037F056E734169891878ED0880231'
assert relay.nickname == 'auth1'
from sbws.util.config import get_config
from sbws.globals import touch_file
import sbws.core.cleanup
from tests.globals import monotonic_time
from tests.unit.globals import monotonic_time
from unittest.mock import patch
import logging
import os
......
......@@ -6,7 +6,7 @@ from sbws.lib.resultdump import Result
from sbws.lib.resultdump import write_result_to_datadir
import sbws.core.init
import sbws.core.stats
from tests.globals import monotonic_time
from tests.unit.globals import monotonic_time
from unittest.mock import patch
from datetime import datetime
import os
......
......@@ -7,7 +7,7 @@ from sbws.lib.resultdump import ResultErrorAuth
from sbws.lib.resultdump import ResultErrorCircuit
from sbws.lib.resultdump import ResultErrorStream
from sbws.lib.resultdump import _ResultType
from tests.globals import monotonic_time
from tests.unit.globals import monotonic_time
@patch('time.time')
......
[tox]
skip_missing_interpreters = True
envlist = clean, lint, py34, py35, py36, stats
envlist = clean, lint, py34, py35, py36, stats, integration
[travis]
python =
3.4: lint, py34
3.4: lint, py34, integration
3.5: py35, integration
3.6: py36, integration
[testenv:clean]
skip_install = True
......@@ -14,6 +16,24 @@ deps =
commands=
coverage erase
[testenv:integration]
ignore_errors = True
deps = .[test]
whitelist_externals =
rm
tar
time
bash
sleep
changedir = {toxinidir}/tests/testnets
commands =
rm -vrf reproducible
tar vxf reproducible.tar
bash ./reproducible/start.sh
time bash -c "python3 ./reproducible/wait.py ./reproducible/{auth,relay,exit}*"
coverage run --rcfile={toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests/integration -vv
bash ./reproducible/stop.sh
[testenv:lint]
skip_install = True
deps = .[dev]
......@@ -36,7 +56,7 @@ install_command =
pip install --process-dependency-links {opts} {packages}
deps = .[test]
commands =
coverage run --rcfile={toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests -vv
coverage run --rcfile={toxinidir}/.coveragerc --source=sbws -m pytest -s {toxinidir}/tests/unit -vv
passenv =
TRAVIS
TRAVIS_JOB_ID
......
Supports Markdown
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