[tor-commits] [ooni-probe/master] Refactor postProcessor to accommodate result callback refactoring.

art at torproject.org art at torproject.org
Sat Nov 23 11:11:41 UTC 2013


commit 2f232b9fac40f949bbad248c4861e7a1b403c493
Author: aagbsn <aagbsn at extc.org>
Date:   Mon Nov 18 14:45:10 2013 +0000

    Refactor postProcessor to accommodate result callback refactoring.
---
 ooni/nettests/blocking/http_requests.py |   36 ++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/ooni/nettests/blocking/http_requests.py b/ooni/nettests/blocking/http_requests.py
index 20fae42..c3c72af 100644
--- a/ooni/nettests/blocking/http_requests.py
+++ b/ooni/nettests/blocking/http_requests.py
@@ -5,7 +5,7 @@
 
 import random
 from twisted.internet import defer
-from twisted.python import usage
+from twisted.python import usage, failure
 
 from ooni.utils import log
 from ooni.utils.net import userAgents
@@ -91,27 +91,33 @@ class HTTPRequestsTest(httpt.HTTPTest):
             self.report['headers_diff'] = diff
             self.report['headers_match'] = True
 
-    @defer.inlineCallbacks
     def test_get_experiment(self):
         log.msg("Performing GET request to %s" % self.url)
-        self.experiment = yield self.doRequest(self.url, method="GET",
+        return  self.doRequest(self.url, method="GET",
                 use_tor=False, headers=self.headers)
 
-    @defer.inlineCallbacks
     def test_get_control(self):
         log.msg("Performing GET request to %s over Tor" % self.url)
-        self.control = yield self.doRequest(self.url, method="GET",
+        return self.doRequest(self.url, method="GET",
                 use_tor=True, headers=self.headers)
 
     def postProcessor(self, measurements):
-        if self.experiment and self.control:
-            self.compare_body_lengths(len(self.control.body),
-                    len(self.experiment.body))
-            self.compare_headers(self.control.headers,
-                    self.experiment.headers)
-
-        if not self.control:
-            self.report['control_failure'] = failureToString(self.control)
-        if not self.experiment:
-            self.report['experiment_failure'] = failureToString(self.experiment)
+        experiment = control = None
+        for status, measurement in measurements:
+            if 'experiment' in str(measurement.netTestMethod):
+                if isinstance(measurement.result, failure.Failure):
+                    self.report['experiment_failure'] = failureToString(measurement.result)
+                else:
+                    experiment = measurement.result
+            elif 'control' in str(measurement.netTestMethod):
+                if isinstance(measurement.result, failure.Failure):
+                    self.report['control_failure'] = failureToString(measurement.result)
+                else:
+                    control = measurement.result
+
+        if experiment and control:
+            self.compare_body_lengths(len(control.body),
+                    len(experiment.body))
+            self.compare_headers(control.headers,
+                    experiment.headers)
         return self.report





More information about the tor-commits mailing list