[tor-commits] [ooni-probe/master] Work in progress on Reporter and NetTest

isis at torproject.org isis at torproject.org
Sun Mar 10 01:57:01 UTC 2013


commit 2d0dc1b57f0e1f407749d6f3c22f233f43e618b3
Author: Arturo Filastò <art at fuffa.org>
Date:   Mon Jan 14 18:25:00 2013 +0100

    Work in progress on Reporter and NetTest
---
 ooni/nettest.py        |   13 +++++++++----
 ooni/reporter.py       |   15 +++++++++++----
 tests/test_director.py |    1 +
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/ooni/nettest.py b/ooni/nettest.py
index 31f2956..67a793d 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -35,11 +35,11 @@ class NetTest(object):
         # This should fire when all the measurements have been completed and
         # all the reports are done. Done means that they have either completed
         # successfully or all the possible retries have been reached.
-        # self.done = defer.DeferredList([self.allMeasurementsDone,
-        #     self.allReportsDone])
+        self.done = defer.DeferredList([self.allMeasurementsDone,
+            self.allReportsDone])
 
         # XXX Fire the done when also all the reporting tasks have been completed.
-        self.done = self.allMeasurementsDone
+        # self.done = self.allMeasurementsDone
 
     def start(self):
         """
@@ -135,7 +135,6 @@ class NetTest(object):
         This is a generator that yields measurements and sets their timeout
         value and their netTest attribute.
         """
-
         task_mediator = TaskMediator(self.allMeasurementsDone)
         for test_class, test_method in self.test_cases:
             for test_input in test_class.inputs:
@@ -145,6 +144,12 @@ class NetTest(object):
                 yield measurement
         task_mediator.allTasksScheduled()
 
+        # Once all the MeasurementsTasks have been completed all the report
+        # tasks will have been scheduled.
+        @task_mediator.allTasksDone.addCallback
+        def done(result):
+            self.report.report_mediator.allTasksScheduled()
+
     def setUpNetTestCases(self):
         """
         Call processTest and processOptions methods of each NetTestCase
diff --git a/ooni/reporter.py b/ooni/reporter.py
index b3a7244..38e83c3 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -375,6 +375,9 @@ class OONIBReporter(OReporter):
         self.backend_version = parsed_response['backend_version']
         log.debug("Created report with id %s" % parsed_response['report_id'])
 
+class ReportClosed(Exception):
+    pass
+
 class Report(object):
     reportEntryManager = None
 
@@ -407,14 +410,18 @@ class Report(object):
 
     def write(self, measurement):
         """
-        This will write to all the reporters, by waiting on the created
-        callback to fire.
+        This is a lazy call that will write to all the reporters by waiting on
+        the created callback to fire.
+
+        The report_write_task is created before we attach the callback so that
+        the report mediator is aware of the total number of created reportEntry
+        tasks.
         """
         for reporter in self.reporters:
+            report_write_task = ReportEntry(reporter, measurement,
+                    self.report_mediator)
             @reporter.created.addCallback
             def cb(result):
-                report_write_task = ReportEntry(reporter, measurement,
-                        self.report_mediator)
                 self.reportEntryManager.schedule(report_write_task)
 
     def finish(self):
diff --git a/tests/test_director.py b/tests/test_director.py
index fa13d9e..0721a2d 100644
--- a/tests/test_director.py
+++ b/tests/test_director.py
@@ -40,6 +40,7 @@ class MockReporter(object):
         pass
 
 class TestDirector(unittest.TestCase):
+    timeout = 1
     def setUp(self):
         with open('dummyInputFile.txt', 'w') as f:
             for i in range(10):





More information about the tor-commits mailing list