Commit 31cfe7a3 authored by juga  's avatar juga
Browse files

Fix tests that relay on the number of header lines

parent 7e0102f9
......@@ -8,6 +8,7 @@ import logging
log = logging.getLogger(__name__)
NUM_LINES_HEADER = 4
def test_generate_no_dotsbws(tmpdir, caplog, parser):
caplog.set_level(logging.DEBUG)
......@@ -96,20 +97,20 @@ def test_generate_single_success_noscale(dotsbws_success_result, caplog,
'should be a success'
captured = capfd.readouterr()
stdout_lines = captured.out.strip().split('\n')
assert len(stdout_lines) == 3
assert len(stdout_lines) == 1 + NUM_LINES_HEADER
# XXX: after mocking time, make sure first line is the current timestamp
# assert stdout_lines[0] is current timestamp
v = 'version={}'.format(version)
assert stdout_lines[1] == v
# FIXME: this is now down in V3BwHeader
# v = 'version={}'.format(version)
# assert stdout_lines[1] == v
bw = round(median([dl['amount'] / dl['duration'] / 1024
for dl in result.downloads]))
rtt = median([round(r * 1000) for r in result.rtts])
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
result.fingerprint, bw, result.nickname, rtt, round(result.time))
assert stdout_lines[2] == bw_line
assert stdout_lines[NUM_LINES_HEADER] == bw_line
def test_generate_single_success_scale(dotsbws_success_result, parser,
......@@ -128,19 +129,19 @@ def test_generate_single_success_scale(dotsbws_success_result, parser,
'should be a success'
captured = capfd.readouterr()
stdout_lines = captured.out.strip().split('\n')
assert len(stdout_lines) == 3
assert len(stdout_lines) == 1 + NUM_LINES_HEADER
# XXX: after mocking time, make sure first line is the current timestamp
# assert stdout_lines[0] is current timestamp
v = 'version={}'.format(version)
assert stdout_lines[1] == v
# FIXME: this is now down in V3BwHeader
# v = 'version={}'.format(version)
# assert stdout_lines[1] == v
bw = 7500
rtt = median([round(r * 1000) for r in result.rtts])
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
result.fingerprint, bw, result.nickname, rtt, round(result.time))
assert stdout_lines[2] == bw_line
assert stdout_lines[NUM_LINES_HEADER] == bw_line
def test_generate_single_relay_success_noscale(
......@@ -158,13 +159,13 @@ def test_generate_single_relay_success_noscale(
'should be a success'
captured = capfd.readouterr()
stdout_lines = captured.out.strip().split('\n')
assert len(stdout_lines) == 3
assert len(stdout_lines) == 1 + NUM_LINES_HEADER
# XXX: after mocking time, make sure first line is the current timestamp
# assert stdout_lines[0] is current timestamp
v = 'version={}'.format(version)
assert stdout_lines[1] == v
# FIXME: this is now down in V3BwHeader
# v = 'version={}'.format(version)
# assert stdout_lines[1] == v
speeds = [dl['amount'] / dl['duration'] / 1024
for r in results for dl in r.downloads]
......@@ -172,7 +173,7 @@ def test_generate_single_relay_success_noscale(
rtt = round(median([round(r * 1000) for r in result.rtts]))
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
result.fingerprint, speed, result.nickname, rtt, round(result.time))
assert stdout_lines[2] == bw_line
assert stdout_lines[NUM_LINES_HEADER] == bw_line
def test_generate_single_relay_success_scale(
......@@ -191,19 +192,19 @@ def test_generate_single_relay_success_scale(
'should be a success'
captured = capfd.readouterr()
stdout_lines = captured.out.strip().split('\n')
assert len(stdout_lines) == 3
assert len(stdout_lines) == 1 + NUM_LINES_HEADER
# XXX: after mocking time, make sure first line is the current timestamp
# assert stdout_lines[0] is current timestamp
v = 'version={}'.format(version)
assert stdout_lines[1] == v
# FIXME: this is now down in V3BwHeader
# v = 'version={}'.format(version)
# assert stdout_lines[1] == v
speed = 7500
rtt = round(median([round(r * 1000) for r in result.rtts]))
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
result.fingerprint, speed, result.nickname, rtt, round(result.time))
assert stdout_lines[2] == bw_line
assert stdout_lines[NUM_LINES_HEADER] == bw_line
def test_generate_two_relays_success_noscale(
......@@ -221,13 +222,13 @@ def test_generate_two_relays_success_noscale(
'should be a success'
captured = capfd.readouterr()
stdout_lines = captured.out.strip().split('\n')
assert len(stdout_lines) == 4
assert len(stdout_lines) == 2 + NUM_LINES_HEADER
# XXX: after mocking time, make sure first line is the current timestamp
# assert stdout_lines[0] is current timestamp
v = 'version={}'.format(version)
assert stdout_lines[1] == v
# FIXME: this is now down in V3BwHeader
# v = 'version={}'.format(version)
# assert stdout_lines[1] == v
r1_results = [r for r in results if r.fingerprint == 'A' * 40]
r1_time = round(max([r.time for r in r1_results]))
......@@ -240,7 +241,7 @@ def test_generate_two_relays_success_noscale(
for rtt in r.rtts]))
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
r1_fingerprint, r1_speed, r1_name, r1_rtt, r1_time)
assert stdout_lines[3] == bw_line
assert stdout_lines[1 + NUM_LINES_HEADER] == bw_line
r2_results = [r for r in results if r.fingerprint == 'B' * 40]
r2_time = round(max([r.time for r in r2_results]))
......@@ -253,4 +254,4 @@ def test_generate_two_relays_success_noscale(
for rtt in r.rtts]))
bw_line = 'node_id=${} bw={} nick={} rtt={} time={}'.format(
r2_fingerprint, r2_speed, r2_name, r2_rtt, r2_time)
assert stdout_lines[2] == bw_line
assert stdout_lines[NUM_LINES_HEADER] == bw_line
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