Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
Metrics
Onionperf
Commits
3e67cb32
Commit
3e67cb32
authored
Jul 13, 2020
by
Karsten Loesing
Browse files
Fix unit tests.
parent
272cd255
Changes
1
Hide whitespace changes
Inline
Side-by-side
onionperf/tests/test_analysis.py
View file @
3e67cb32
import
os
import
pkg_resources
from
nose.tools
import
*
from
onionperf
import
analysis
,
util
from
onionperf
import
util
from
tgentools
import
analysis
def
absolute_data_path
(
relative_path
=
""
):
...
...
@@ -12,188 +13,142 @@ def absolute_data_path(relative_path=""):
"tests/data/"
+
relative_path
)
DATA_DIR
=
absolute_data_path
()
LINE_ERROR
=
'2019-04-22 14:41:20 1555940480.647663 [message] [shd-tgen-transfer.c:1504] [_tgentransfer_log] [transfer-error] transport TCP,12,localhost:127.0.0.1:46878,localhost:127.0.0.1:43735,dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080,state=ERROR,error=READ transfer transfer5m,4,cyan,GET,5242880,(null),0,state=ERROR,error=PROXY total-bytes-read=0 total-bytes-write=0 payload-bytes-read=0/5242880 (0.00%) usecs-to-socket-create=11 usecs-to-socket-connect=210 usecs-to-proxy-init=283 usecs-to-proxy-choice=348 usecs-to-proxy-request=412 usecs-to-proxy-response=-1 usecs-to-command=-1 usecs-to-response=-1 usecs-to-first-byte=-1 usecs-to-last-byte=-1 usecs-to-checksum=-1'
NO_PARSE_LINE
=
'2018-04-14 21:10:04 1523740204.809894 [message] [shd-tgen-transfer.c:803] [_tgentransfer_log] [transfer-error] transport TCP,17,NULL:37.218.247.40:26006,NULL:0.0.0.0:0,146.0.73.4:146.0.73.4:1313,state=SUCCESS,error=NONE transfer (null),26847,op-nl,NONE,0,(null),0,state=ERROR,error=AUTH total-bytes-read=1 total-bytes-write=0 payload-bytes-write=0/0 (-nan%) usecs-to-socket-create=0 usecs-to-socket-connect=8053676879205 usecs-to-proxy-init=-1 usecs-to-proxy-choice=-1 usecs-to-proxy-request=-1 usecs-to-proxy-response=-1 usecs-to-command=-1 usecs-to-response=-1 usecs-to-first-byte=-1 usecs-to-last-byte=-1 usecs-to-checksum=-1'
def
test_transfer_status_event
():
transfer
=
analysis
.
TransferStatusEvent
(
LINE_ERROR
)
assert_equals
(
transfer
.
is_success
,
False
)
assert_equals
(
transfer
.
is_error
,
False
)
assert_equals
(
transfer
.
is_complete
,
False
)
assert_equals
(
transfer
.
unix_ts_end
,
1555940480.647663
)
assert_equals
(
transfer
.
endpoint_local
,
'localhost:127.0.0.1:46878'
)
assert_equals
(
transfer
.
endpoint_proxy
,
'localhost:127.0.0.1:43735'
)
assert_equals
(
transfer
.
endpoint_remote
,
'dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080'
)
LINE_ERROR
=
'2019-04-22 14:41:20 1555940480.647663 [message] [tgen-stream.c:1618] [_tgenstream_log] [stream-error] transport [fd=12,local=localhost:127.0.0.1:46878,proxy=localhost:127.0.0.1:43735,remote=dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080,state=ERROR,error=READ] stream [id=4,vertexid=stream5m,name=cyan,peername=(null),sendsize=0,recvsize=5242880,sendstate=SEND_COMMAND,recvstate=RECV_NONE,error=PROXY] bytes [total-bytes-recv=0,total-bytes-send=0,payload-bytes-recv=0,payload-bytes-send=0,payload-progress-recv=0.00%,payload-progress-send=100.00%] times [created-ts=5948325159988,usecs-to-socket-create=11,usecs-to-socket-connect=210,usecs-to-proxy-init=283,usecs-to-proxy-choice=348,usecs-to-proxy-request=412,usecs-to-proxy-response=-1,usecs-to-command=-1,usecs-to-response=-1,usecs-to-first-byte-recv=-1,usecs-to-last-byte-recv=-1,usecs-to-checksum-recv=-1,usecs-to-first-byte-send=-1,usecs-to-last-byte-send=-1,usecs-to-checksum-send=-1,now-ts=5948446579043]'
NO_PARSE_LINE
=
'2018-04-14 21:10:04 1523740204.809894 [message] [tgen-stream.c:1618] [_tgenstream_log] [stream-error] transport [fd=17,local=localhost:127.0.0.1:46878,proxy=localhost:127.0.0.1:43735,remote=dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080,state=SUCCESS,error=NONE] stream [id=4,vertexid=stream5m,name=cyan,peername=(null),sendsize=0,recvsize=5242880,sendstate=SEND_COMMAND,recvstate=RECV_NONE,error=PROXY] bytes [total-bytes-recv=1,total-bytes-send=0,payload-bytes-recv=0,payload-bytes-send=0,payload-progress-recv=0.00%,payload-progress-send=100.00%] times [created-ts=5948325159988,usecs-to-socket-create=0,usecs-to-socket-connect=210,usecs-to-proxy-init=-1,usecs-to-proxy-choice=-1,usecs-to-proxy-request=-1,usecs-to-proxy-response=-1,usecs-to-command=-1,usecs-to-response=-1,usecs-to-first-byte-recv=-1,usecs-to-last-byte-recv=-1,usecs-to-checksum-recv=-1,usecs-to-first-byte-send=-1,usecs-to-last-byte-send=-1,usecs-to-checksum-send=-1,now-ts=5948446579043]'
def
test_stream_status_event
():
stream
=
analysis
.
StreamStatusEvent
(
LINE_ERROR
)
assert_equals
(
stream
.
is_success
,
False
)
assert_equals
(
stream
.
is_error
,
False
)
assert_equals
(
stream
.
is_complete
,
False
)
assert_equals
(
stream
.
unix_ts_end
,
1555940480.647663
)
assert_equals
(
stream
.
transport_info
[
'local'
],
'localhost:127.0.0.1:46878'
)
assert_equals
(
stream
.
transport_info
[
'proxy'
],
'localhost:127.0.0.1:43735'
)
assert_equals
(
transfer
.
endpoint_
remote
,
stream
.
transport_info
[
'
remote
'
]
,
'dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080'
)
assert_equals
(
transfer
.
transfer_id
,
'transfer5m:4'
)
assert_equals
(
transfer
.
hostname_local
,
'cyan'
)
assert_equals
(
transfer
.
method
,
'GET'
)
assert_equals
(
transfer
.
filesize_bytes
,
5242880
)
assert_equals
(
transfer
.
hostname_remote
,
'(null)'
)
assert_equals
(
transfer
.
error_code
,
'PROXY'
)
assert_equals
(
transfer
.
total_bytes_read
,
0
)
assert_equals
(
transfer
.
total_bytes_write
,
0
)
assert_equals
(
transfer
.
is_commander
,
True
)
assert_equals
(
transfer
.
payload_bytes_status
,
0
)
assert_equals
(
transfer
.
unconsumed_parts
,
[
'usecs-to-socket-create=11'
,
'usecs-to-socket-connect=210'
,
'usecs-to-proxy-init=283'
,
'usecs-to-proxy-choice=348'
,
'usecs-to-proxy-request=412'
,
'usecs-to-proxy-response=-1'
,
'usecs-to-command=-1'
,
'usecs-to-response=-1'
,
'usecs-to-first-byte=-1'
,
'usecs-to-last-byte=-1'
,
'usecs-to-checksum=-1'
])
assert_equals
(
transfer
.
elapsed_seconds
,
{})
def
test_transfer_complete_event_init
():
complete
=
analysis
.
TransferCompleteEvent
(
LINE_ERROR
)
assert_equals
(
stream
.
stream_id
,
'4:12:localhost:127.0.0.1:46878:dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080'
)
assert_equals
(
stream
.
stream_info
[
'name'
],
'cyan'
)
assert_equals
(
stream
.
stream_info
[
'recvsize'
],
'5242880'
)
assert_equals
(
stream
.
stream_info
[
'peername'
],
'(null)'
)
assert_equals
(
stream
.
stream_info
[
'error'
],
'PROXY'
)
assert_equals
(
stream
.
byte_info
[
'total-bytes-recv'
],
'0'
)
assert_equals
(
stream
.
byte_info
[
'total-bytes-send'
],
'0'
)
assert_equals
(
stream
.
byte_info
[
'payload-bytes-recv'
],
'0'
)
def
test_stream_complete_event_init
():
complete
=
analysis
.
StreamCompleteEvent
(
LINE_ERROR
)
assert_equals
(
complete
.
is_complete
,
True
)
assert_equals
(
complete
.
elapsed_seconds
,
{
'proxy_init'
:
0.000283
,
'proxy_request'
:
0.000412
,
'proxy_choice'
:
0.000348
,
'socket_connect'
:
0.00021
,
'socket_create'
:
1.1e-05
})
assert_equals
(
complete
.
time_info
[
'usecs-to-proxy-init'
],
'283'
)
assert_equals
(
complete
.
time_info
[
'usecs-to-proxy-request'
],
'412'
)
assert_equals
(
complete
.
time_info
[
'usecs-to-proxy-choice'
],
'348'
)
assert_equals
(
complete
.
time_info
[
'usecs-to-socket-connect'
],
'210'
)
assert_equals
(
complete
.
time_info
[
'usecs-to-socket-create'
],
'11'
)
assert_equals
(
complete
.
unix_ts_start
,
1555940480.6472511
)
def
test_tr
ansfer
_error_event
():
error
=
analysis
.
Transfer
ErrorEvent
(
LINE_ERROR
)
def
test_
s
tr
eam
_error_event
():
error
=
analysis
.
Stream
ErrorEvent
(
LINE_ERROR
)
assert_equals
(
error
.
is_error
,
True
)
assert_equals
(
error
.
is_success
,
False
)
def
test_tr
ansfer
_success_event_init
():
success
=
analysis
.
Transfer
SuccessEvent
(
LINE_ERROR
)
def
test_
s
tr
eam
_success_event_init
():
success
=
analysis
.
Stream
SuccessEvent
(
LINE_ERROR
)
assert_equals
(
success
.
is_success
,
True
)
def
test_transfer_object_init
():
error
=
analysis
.
TransferErrorEvent
(
LINE_ERROR
)
t
=
analysis
.
Transfer
(
error
.
transfer_id
)
assert_equals
(
t
.
id
,
'transfer5m:4'
)
assert_equals
(
t
.
last_event
,
None
)
assert_equals
(
t
.
payload_progress
,
{
0.0
:
None
,
0.1
:
None
,
0.2
:
None
,
0.3
:
None
,
0.4
:
None
,
0.5
:
None
,
0.6
:
None
,
0.7
:
None
,
0.8
:
None
,
0.9
:
None
,
1.0
:
None
})
def
test_stream_object_init
():
error
=
analysis
.
StreamErrorEvent
(
LINE_ERROR
)
s
=
analysis
.
Stream
(
error
.
stream_id
)
assert_equals
(
s
.
id
,
'4:12:localhost:127.0.0.1:46878:dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080'
)
assert_equals
(
s
.
last_event
,
None
)
def
test_transfer_object_add_event
():
error
=
analysis
.
TransferErrorEvent
(
LINE_ERROR
)
t
=
analysis
.
Transfer
(
error
.
transfer_id
)
t
.
add_event
(
error
)
assert_equals
(
t
.
last_event
,
error
)
assert_equals
(
t
.
payload_progress
,
{
0.0
:
1555940480.647663
,
0.1
:
None
,
0.2
:
None
,
0.3
:
None
,
0.4
:
None
,
0.5
:
None
,
0.6
:
None
,
0.7
:
None
,
0.8
:
None
,
0.9
:
None
,
1.0
:
None
})
def
test_stream_object_add_event
():
error
=
analysis
.
StreamErrorEvent
(
LINE_ERROR
)
s
=
analysis
.
Stream
(
error
.
stream_id
)
s
.
add_event
(
error
)
assert_equals
(
s
.
last_event
,
error
)
@
raises
(
KeyError
)
def
test_tr
ansfer
_object_get_data_error
():
error
=
analysis
.
Transfer
ErrorEvent
(
LINE_ERROR
)
t
=
analysis
.
Transfer
(
error
.
tr
ansfer
_id
)
t
.
add_event
(
error
)
t
.
get_data
()[
'elapsed_seconds'
][
'payload_progress'
]
def
test_
s
tr
eam
_object_get_data_error
():
error
=
analysis
.
Stream
ErrorEvent
(
LINE_ERROR
)
s
=
analysis
.
Stream
(
error
.
s
tr
eam
_id
)
s
.
add_event
(
error
)
s
.
get_data
()[
'elapsed_seconds'
][
'payload_progress
_recv
'
]
def
test_tr
ansfer
_object_get_data_no_error
():
success
=
analysis
.
Transfer
SuccessEvent
(
LINE_ERROR
)
t
=
analysis
.
Transfer
(
success
.
tr
ansfer
_id
)
t
.
add_event
(
success
)
def
test_
s
tr
eam
_object_get_data_no_error
():
success
=
analysis
.
Stream
SuccessEvent
(
LINE_ERROR
)
s
=
analysis
.
Stream
(
success
.
s
tr
eam
_id
)
s
.
add_event
(
success
)
assert_true
(
t
.
get_data
()[
'elapsed_seconds'
][
'payload_progress'
]
is
not
None
)
s
.
get_data
()[
'elapsed_seconds'
][
'payload_progress
_recv
'
]
is
not
None
)
def
test_tr
ansfer
_object_end_to_end
():
error
=
analysis
.
Transfer
ErrorEvent
(
LINE_ERROR
)
t
=
analysis
.
Transfer
(
error
.
tr
ansfer
_id
)
t
.
add_event
(
error
)
def
test_
s
tr
eam
_object_end_to_end
():
error
=
analysis
.
Stream
ErrorEvent
(
LINE_ERROR
)
s
=
analysis
.
Stream
(
error
.
s
tr
eam
_id
)
s
.
add_event
(
error
)
assert_equals
(
t
.
get_data
(),
{
'is_
error'
:
True
,
'
endpoint_local'
:
'
localhost:127.0.0.1:46878'
,
't
otal_bytes_read'
:
0
,
'error_code'
:
'PROXY
'
,
'unix_ts_end'
:
1555940480.647663
,
'
hostname_local'
:
'cyan
'
,
'endpoint_remote'
:
'dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080
'
,
'elapsed_seconds'
:
{
'
proxy_init'
:
0.000283
,
'
proxy_request'
:
0.000412
,
'
proxy_choice'
:
0.000348
,
'
socket_connect'
:
0.00021
,
'
socket_create'
:
1.1e-05
s
.
get_data
(),
{
'is_
success'
:
False
,
'is_error'
:
True
,
'
is_complete'
:
True
,
'
unix_ts_end'
:
1555940480.647663
,
't
ransport_info'
:
{
'fd'
:
'12'
,
'local'
:
'localhost:127.0.0.1:46878'
,
'proxy'
:
'localhost:127.0.0.1:43735'
,
'remote'
:
'dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080
'
,
'state'
:
'ERROR'
,
'error'
:
'READ'
}
,
'
stream_info'
:
{
'id'
:
'4
'
,
'vertexid'
:
'stream5m'
,
'name'
:
'cyan
'
,
'peername'
:
'(null)'
,
'
sendsize'
:
'0'
,
'
recvsize'
:
'5242880'
,
'
sendstate'
:
'SEND_COMMAND'
,
'
recvstate'
:
'RECV_NONE'
,
'
error'
:
'PROXY'
},
'method'
:
'GET'
,
'is_commander'
:
True
,
'total_bytes_write'
:
0
,
'unix_ts_start'
:
1555940480.6472511
,
'hostname_remote'
:
'(null)'
,
'transfer_id'
:
'transfer5m:4'
,
'is_success'
:
False
,
'payload_bytes_status'
:
0
,
'endpoint_proxy'
:
'localhost:127.0.0.1:43735'
,
'is_complete'
:
True
,
'filesize_bytes'
:
5242880
'byte_info'
:
{
'total-bytes-recv'
:
'0'
,
'total-bytes-send'
:
'0'
,
'payload-bytes-recv'
:
'0'
,
'payload-bytes-send'
:
'0'
,
'payload-progress-recv'
:
'0.00%'
,
'payload-progress-send'
:
'100.00%'
},
'time_info'
:
{
'created-ts'
:
'5948325159988'
,
'usecs-to-socket-create'
:
'11'
,
'usecs-to-socket-connect'
:
'210'
,
'usecs-to-proxy-init'
:
'283'
,
'usecs-to-proxy-choice'
:
'348'
,
'usecs-to-proxy-request'
:
'412'
,
'usecs-to-proxy-response'
:
'-1'
,
'usecs-to-command'
:
'-1'
,
'usecs-to-response'
:
'-1'
,
'usecs-to-first-byte-recv'
:
'-1'
,
'usecs-to-last-byte-recv'
:
'-1'
,
'usecs-to-checksum-recv'
:
'-1'
,
'usecs-to-first-byte-send'
:
'-1'
,
'usecs-to-last-byte-send'
:
'-1'
,
'usecs-to-checksum-send'
:
'-1'
,
'now-ts'
:
'5948446579043'
},
'stream_id'
:
'4:12:localhost:127.0.0.1:46878:dc34og3c3aqdqntblnxkstzfvh7iy7llojd4fi5j23y2po32ock2k7ad.onion:0.0.0.0:8080'
,
'unix_ts_start'
:
1555940480.6472511
})
@
raises
(
ZeroDivisionError
)
def
test_transfer_status_parse_error
():
transfer
=
analysis
.
TransferStatusEvent
(
NO_PARSE_LINE
)
t
=
analysis
.
Transfer
(
transfer
.
transfer_id
)
t
.
add_event
(
transfer
)
def
test_parsing_parse_error
():
parser
=
analysis
.
TGenParser
()
parser
.
parse
(
util
.
DataSource
(
DATA_DIR
+
'parse_error'
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment