[tor-commits] [ooni-probe/master] Handle exceptions better inside of httpt test template
art at torproject.org
art at torproject.org
Thu Aug 14 11:34:05 UTC 2014
commit dc7cc8fea556ed9391147defb7624110ab48133d
Author: Arturo Filastò <art at fuffa.org>
Date: Thu Aug 14 13:26:24 2014 +0200
Handle exceptions better inside of httpt test template
---
ooni/nettests/blocking/http_requests.py | 6 ++++--
ooni/templates/httpt.py | 8 ++++++++
ooni/utils/net.py | 1 -
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ooni/nettests/blocking/http_requests.py b/ooni/nettests/blocking/http_requests.py
index dd74b6c..625f34c 100644
--- a/ooni/nettests/blocking/http_requests.py
+++ b/ooni/nettests/blocking/http_requests.py
@@ -115,13 +115,15 @@ class HTTPRequestsTest(httpt.HTTPTest):
def postProcessor(self, measurements):
experiment = control = None
for status, measurement in measurements:
- if 'experiment' in str(measurement.netTestMethod):
+ net_test_method = measurement.netTestMethod.im_func.func_name
+
+ if net_test_method == "test_get_experiment":
if isinstance(measurement.result, failure.Failure):
self.report['experiment_failure'] = failureToString(
measurement.result)
else:
experiment = measurement.result
- elif 'control' in str(measurement.netTestMethod):
+ elif net_test_method == "test_get_control":
if isinstance(measurement.result, failure.Failure):
self.report['control_failure'] = failureToString(
measurement.result)
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index 59b550e..18b0d81 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -154,6 +154,12 @@ class HTTPTest(NetTestCase):
response.body = response_body
return response
+ def _processResponseBodyFail(self, failure, request):
+ failure_string = handleAllFailures(failure)
+ HTTPTest.addToReport(self, request, response,
+ failure_string=failure_string)
+ return response
+
def processResponseBody(self, body):
"""
Overwrite this method if you wish to interact with the response body of
@@ -242,6 +248,8 @@ class HTTPTest(NetTestCase):
response.deliverBody(BodyReceiver(finished, content_length))
finished.addCallback(self._processResponseBody, request,
response, body_processor)
+ finished.addErrback(self._processResponseBodyFail, request,
+ response)
return finished
def doRequest(self, url, method="GET",
diff --git a/ooni/utils/net.py b/ooni/utils/net.py
index 69e39d6..7580616 100644
--- a/ooni/utils/net.py
+++ b/ooni/utils/net.py
@@ -4,7 +4,6 @@ from random import randint
from zope.interface import implements
from twisted.internet import protocol, defer
-from twisted.internet import threads, reactor
from twisted.web.iweb import IBodyProducer
from ooni.utils import log
More information about the tor-commits
mailing list