Skip to content

Commit

Permalink
Add protocol latency tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Apr 12, 2016
1 parent e6bfa73 commit 91fcbd1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,10 @@ def net(request):
n = _Network()
request.addfinalizer(n.close)
return n

def pytest_addoption(parser):
parser.addoption('--vmdebug', action='store_true', help='run `test_debug` test')

def pytest_cmdline_preparse(args):
if '--vmdebug' in args:
args[:] = ['-k', 'test_vmdebug'] + args
2 changes: 1 addition & 1 deletion tests/regw/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:14.04
RUN set -o xtrace \
&& sed -i 's,^deb-src,# no src # &,; s,http://archive.ubuntu.com/ubuntu/,mirror://mirrors.ubuntu.com/mirrors.txt,' /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y libevent-2.0-5 valgrind
&& apt-get install -y libevent-2.0-5 valgrind curl

COPY redsocks /usr/local/sbin/
COPY redsocks.conf /usr/local/etc/
Expand Down
2 changes: 1 addition & 1 deletion tests/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

exec py.test -v
exec py.test -v "$@"
47 changes: 44 additions & 3 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,53 @@
import conftest
import pytest

#@pytest.skip # used for debugging
#def test_sleep(net):
# check_call('sleep 1h'.split())
@pytest.mark.skipif(not pytest.config.getoption('--vmdebug'), reason='need --vmdebug option to run')
def test_vmdebug(net):
check_call('sleep 365d'.split())

@pytest.mark.parametrize('tank', conftest.TANKS.keys())
def test_smoke(net, tank):
vm = net.vm['tank%d' % conftest.TANKS[tank]]
page = vm.do('curl --max-time 0.5 http://10.0.1.80/')
assert 'Welcome to nginx!' in page

RTT = 200 # ms

@pytest.fixture(scope="function")
def slow_net(request, net):
def close():
net.vm['gw'].netcall('tc qdisc del dev ethx root')
net.vm['gw'].netcall('tc qdisc del dev ethw root')
request.addfinalizer(close)
net.vm['gw'].netcall('tc qdisc add dev ethw root netem delay %dms' % (RTT / 2))
net.vm['gw'].netcall('tc qdisc add dev ethx root netem delay %dms' % (RTT / 2))
return net

LATENCY = {
'connect_none': 3 * RTT,
'connect_basic': 3 * RTT,
'connect_digest': 3 * RTT,
'socks5_none': 4 * RTT,
'socks5_auth': 5 * RTT,
'regw_direct': 2 * RTT,
}

def http_ping(vm):
vm.do('curl -o /dev/null http://10.0.1.80/') # heatup L2 and auth caches
s = vm.do('curl -sS -w %{{time_connect}}/%{{time_total}}/%{{http_code}}/%{{size_download}} -o /dev/null http://10.0.1.80/')
connect, total, code, size = s.split('/')
connect, total, code, size = float(connect) * 1000, float(total) * 1000, int(code), int(size)
return connect, total, code, size

@pytest.mark.parametrize('tank', conftest.TANKS.keys())
def test_latency_tank(slow_net, tank):
vm = slow_net.vm['tank%d' % conftest.TANKS[tank]]
connect, total, code, size = http_ping(vm)
assert code == 200 and size == 612
assert connect < 0.005 and LATENCY[tank]-RTT*.2 < total and total < LATENCY[tank]+RTT*.2

def test_latency_regw(slow_net):
vm, tank = slow_net.vm['regw'], 'regw_direct'
connect, total, code, size = http_ping(vm)
assert code == 200 and size == 612
assert RTT*.8 < connect and connect < RTT*1.2 and LATENCY[tank]-RTT*.2 < total and total < LATENCY[tank]+RTT*.2

0 comments on commit 91fcbd1

Please sign in to comment.