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

[tor-commits] [ooni-probe/master] Nettests are now running properly with the TaskManager



commit cf274700c3e43f86d30a7fd5eb5cd093dbfc4e0a
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Wed Jan 16 20:58:29 2013 +0100

    Nettests are now running properly with the TaskManager
    
    Issue retries, make tests timeout, etc.
---
 ooni/director.py |    4 ++-
 ooni/errors.py   |    2 +-
 ooni/nettest.py  |   97 +++++++++++++++++++++++++----------------------------
 ooni/reporter.py |    2 -
 4 files changed, 50 insertions(+), 55 deletions(-)

diff --git a/ooni/director.py b/ooni/director.py
index 6fe3859..80cf22c 100644
--- a/ooni/director.py
+++ b/ooni/director.py
@@ -1,6 +1,6 @@
 from ooni.managers import ReportEntryManager, MeasurementManager
 from ooni.reporter import Report
-
+from ooni.utils import log
 from ooni.nettest import NetTest
 
 class Director(object):
@@ -117,11 +117,13 @@ class Director(object):
         self.totalMeasurements += 1
 
     def measurementSucceeded(self, measurement):
+        log.msg("Successfully completed measurement: %s" % measurement)
         self.totalMeasurementRuntime += measurement.runtime
         self.successfulMeasurements += 1
         return measurement.testInstance.report
 
     def measurementFailed(self, failure, measurement):
+        log.msg("Failed doing measurement: %s" % measurement)
         self.totalMeasurementRuntime += measurement.runtime
 
         self.failedMeasurements += 1
diff --git a/ooni/errors.py b/ooni/errors.py
index c7ecfae..cd4a136 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -14,7 +14,7 @@ from txsocksx.errors import HostUnreachable, ConnectionRefused
 from txsocksx.errors import TTLExpired, CommandNotSupported
 
 from socket import gaierror
-
+from ooni.utils import log
 def handleAllFailures(failure):
     """
     Here we make sure to trap all the failures that are supported by the
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 7c4278a..728d093 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -15,51 +15,6 @@ from StringIO import StringIO
 class NoTestCasesFound(Exception):
     pass
 
-class NetTestState(object):
-    def __init__(self, allTasksDone):
-        """
-        This keeps track of the state of a running NetTests case.
-
-        Args:
-            allTasksDone is a deferred that will get fired once all the NetTest
-            cases have reached a final done state.
-        """
-        self.doneTasks = 0
-        self.tasks = 0
-
-        self.completedScheduling = False
-        self.allTasksDone = allTasksDone
-
-    def taskCreated(self):
-        self.tasks += 1
-
-    def checkAllTasksDone(self):
-        if self.completedScheduling and \
-                self.doneTasks == self.tasks:
-            self.allTasksDone.callback(self.doneTasks)
-
-    def taskDone(self):
-        """
-        This is called every time a task has finished running.
-        """
-        self.doneTasks += 1
-        self.checkAllTasksDone()
-
-    def allTasksScheduled(self):
-        """
-        This should be called once all the tasks that need to run have been
-        scheduled.
-
-        XXX this is ghetto.
-        The reason for which we are calling allTasksDone inside of the
-        allTasksScheduled method is called after all tasks are done, then we
-        will run into a race condition. The race is that we don't end up
-        checking that all the tasks are complete because no task is to be
-        scheduled.
-        """
-        self.completedScheduling = True
-        self.checkAllTasksDone()
-
 class NetTestLoader(object):
     method_prefix = 'test'
 
@@ -226,6 +181,51 @@ class NetTestLoader(object):
             pass
         return test_cases
 
+class NetTestState(object):
+    def __init__(self, allTasksDone):
+        """
+        This keeps track of the state of a running NetTests case.
+
+        Args:
+            allTasksDone is a deferred that will get fired once all the NetTest
+            cases have reached a final done state.
+        """
+        self.doneTasks = 0
+        self.tasks = 0
+
+        self.completedScheduling = False
+        self.allTasksDone = allTasksDone
+
+    def taskCreated(self):
+        self.tasks += 1
+
+    def checkAllTasksDone(self):
+        if self.completedScheduling and \
+                self.doneTasks == self.tasks:
+            self.allTasksDone.callback(self.doneTasks)
+
+    def taskDone(self):
+        """
+        This is called every time a task has finished running.
+        """
+        self.doneTasks += 1
+        self.checkAllTasksDone()
+
+    def allTasksScheduled(self):
+        """
+        This should be called once all the tasks that need to run have been
+        scheduled.
+
+        XXX this is ghetto.
+        The reason for which we are calling allTasksDone inside of the
+        allTasksScheduled method is called after all tasks are done, then we
+        will run into a race condition. The race is that we don't end up
+        checking that all the tasks are complete because no task is to be
+        scheduled.
+        """
+        self.completedScheduling = True
+        self.checkAllTasksDone()
+
 class NetTest(object):
     director = None
 
@@ -295,12 +295,7 @@ class NetTest(object):
         """
         self.report.open()
         for test_class, test_method in self.testCases:
-            if not test_class.inputs:
-                # XXX this is a bit dirty, refactor me
-                yield self.makeMeasurement(test_class, test_method)
-                self.state.taskCreated()
-                break
-
+            log.debug("Running %s %s" % (test_class, test_method))
             for test_input in test_class.inputs:
                 measurement = self.makeMeasurement(test_class, test_method,
                         test_input)
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 7d33bd1..30c4817 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -363,8 +363,6 @@ class Report(object):
         self.done.addCallback(self.close)
 
         self.reportEntryManager = reportEntryManager
-        # XXX call this when starting test
-        # self.open()
 
     def open(self):
         """



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