[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionperf/master] Removes unecessary raise and adds unit tests to validate behaviour



commit 60fff2d9a1b212013cc854f00b8e1450eec7ea46
Author: Ana Custura <ana@xxxxxxxxxxxxxx>
Date:   Thu Jun 27 02:04:29 2019 +0100

    Removes unecessary raise and adds unit tests to validate behaviour
---
 onionperf/analysis.py            |  1 -
 onionperf/tests/data/parse_error |  1 +
 onionperf/tests/test_analysis.py | 15 +++++++++++++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/onionperf/analysis.py b/onionperf/analysis.py
index 0bc1811..e90d005 100644
--- a/onionperf/analysis.py
+++ b/onionperf/analysis.py
@@ -532,7 +532,6 @@ class TGenParser(Parser):
                     break
             except:
                 logging.warning("TGenParser: skipping line due to parsing error: {0}".format(line))
-                raise
                 continue
         source.close()
 
diff --git a/onionperf/tests/data/parse_error b/onionperf/tests/data/parse_error
new file mode 100644
index 0000000..3c8cde7
--- /dev/null
+++ b/onionperf/tests/data/parse_error
@@ -0,0 +1 @@
+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
diff --git a/onionperf/tests/test_analysis.py b/onionperf/tests/test_analysis.py
index 150e8f0..6463458 100644
--- a/onionperf/tests/test_analysis.py
+++ b/onionperf/tests/test_analysis.py
@@ -1,7 +1,7 @@
 import os
 import pkg_resources
 from nose.tools import *
-from onionperf import analysis
+from onionperf import analysis, util
 
 
 def absolute_data_path(relative_path=""):
@@ -11,10 +11,10 @@ def absolute_data_path(relative_path=""):
     return pkg_resources.resource_filename("onionperf",
                                            "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)
@@ -186,3 +186,14 @@ def test_transfer_object_end_to_end():
             'filesize_bytes':
             5242880
         })
+
+
+@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'))



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits