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

[tor-commits] [ooni-probe/master] Refactor captive portal test to run tests in threads



commit cfab60ab130742152e5dfb96450e4d625a4da1a8
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Mon Nov 12 16:31:25 2012 +0100

    Refactor captive portal test to run tests in threads
---
 nettests/core/captiveportal.py |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/nettests/core/captiveportal.py b/nettests/core/captiveportal.py
index 66779bb..be8da27 100644
--- a/nettests/core/captiveportal.py
+++ b/nettests/core/captiveportal.py
@@ -37,6 +37,9 @@ import string
 import urllib2
 from urlparse import urlparse
 
+from twisted.python import usage
+from twisted.internet import defer, threads
+
 from ooni import nettest
 from ooni.templates import httpt
 from ooni.utils import net
@@ -52,7 +55,8 @@ except ImportError:
 __plugoo__ = "captiveportal"
 __desc__ = "Captive portal detection test"
 
-optParameters = [['asset', 'a', None, 'Asset file'],
+class UsageOptions(usage.Options):
+    optParameters = [['asset', 'a', None, 'Asset file'],
                  ['experiment-url', 'e', 'http://google.com/', 'Experiment URL'],
                  ['user-agent', 'u', random.choice(net.userAgents),
                   'User agent for HTTP requests']
@@ -66,8 +70,9 @@ class CaptivePortal(nettest.NetTestCase):
 
     name = "captivep"
     description = "Captive Portal Test"
-    version = '0.1'
-    author = "Isis LoveCruft <isis@xxxxxxxxxxxxxx>"
+    version = '0.2'
+    author = "Isis Lovecruft"
+    usageOptions = UsageOptions
 
     def http_fetch(self, url, headers={}):
         """
@@ -424,8 +429,6 @@ class CaptivePortal(nettest.NetTestCase):
         Google Chrome resolves three 10-byte random hostnames.
         """
         subtest = "Google Chrome DNS-based"
-
-        log.msg("")
         log.msg("Running the Google Chrome DNS-based captive portal test...")
 
         gmatch, google_dns_result = self.compare_random_hostnames(3, 10)
@@ -600,6 +603,7 @@ class CaptivePortal(nettest.NetTestCase):
 
             self.report['result'] = False
 
+    @defer.inlineCallbacks
     def test_captive_portal(self):
         """
         Runs the CaptivePortal(Test).
@@ -625,15 +629,15 @@ class CaptivePortal(nettest.NetTestCase):
 
         log.msg("")
         log.msg("Running vendor tests...")
-        self.report['vendor_tests'] = self.run_vendor_tests()
+        self.report['vendor_tests'] = yield threads.deferToThread(self.run_vendor_tests)
 
         log.msg("")
         log.msg("Running vendor DNS-based tests...")
-        self.report['vendor_dns_tests'] = self.run_vendor_dns_tests()
+        self.report['vendor_dns_tests'] = yield threads.deferToThread(self.run_vendor_dns_tests)
 
         log.msg("")
         log.msg("Checking that DNS requests are not being tampered...")
-        self.report['check0x20'] = self.check_0x20_to_auth_ns('ooni.nu')
+        self.report['check0x20'] = yield threads.deferToThread(self.check_0x20_to_auth_ns, 'ooni.nu')
 
         log.msg("")
         log.msg("Captive portal test finished!")

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