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

[tor-commits] [ooni-probe/master] Test if the done callback will fire when all tasks have been completed



commit 77fe44bd5dd5a50f7707c2e2e5a9354339e60d68
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sun Jan 13 20:21:34 2013 +0100

    Test if the done callback will fire when all tasks have been completed
---
 tests/test_managers.py |    1 +
 tests/test_nettest.py  |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/tests/test_managers.py b/tests/test_managers.py
index d24ee5e..9bc0698 100644
--- a/tests/test_managers.py
+++ b/tests/test_managers.py
@@ -52,6 +52,7 @@ class MockTaskManager(TaskManager):
         self.successes.append((result, task))
 
 class TestTaskManager(unittest.TestCase):
+    timeout = 1
     def setUp(self):
         self.measurementManager = MockTaskManager()
         self.measurementManager.concurrency = 10
diff --git a/tests/test_nettest.py b/tests/test_nettest.py
index a23d16b..b7bd365 100644
--- a/tests/test_nettest.py
+++ b/tests/test_nettest.py
@@ -10,6 +10,8 @@ from ooni.nettest import FailureToLoadNetTest
 from ooni.tasks import BaseTask
 from ooni.utils import NotRootError
 
+from ooni.managers import TaskManager
+
 net_test_string = """
 from twisted.python import usage
 from ooni.nettest import NetTestCase
@@ -116,7 +118,22 @@ class DummyReporter(object):
     def write(self, result):
         pass
 
+class MockMeasurementManager(TaskManager):
+    def __init__(self):
+        self.successes = []
+
+    def failed(self, failure, task):
+        pass
+
+    def succeeded(self, result, task):
+        self.successes.append((result, task))
+
+class MockReporter(object):
+    def write(self, measurement):
+        pass
+
 class TestNetTest(unittest.TestCase):
+    timeout = 1
     def setUp(self):
         with open('dummyInputFile.txt', 'w') as f:
             for i in range(10):
@@ -245,6 +262,21 @@ class TestNetTest(unittest.TestCase):
         measurements = list(net_test.generateMeasurements())
         self.assertEqual(len(measurements), 20)
 
+    def test_net_test_completed_callback(self):
+        dummyOptionsWithFile = dict(dummyOptions)
+        dummyOptionsWithFile['file'] = 'dummyInputFile.txt'
+
+        net_test = NetTest(StringIO(net_test_string_with_file),
+            dummyOptionsWithFile, MockReporter())
+        net_test.measurementManager = MockMeasurementManager()
+
+        d = net_test.start()
+        @d.addCallback
+        def complete(result):
+            self.assertEqual(result, None)
+
+        return d
+
     #def test_require_root_succeed(self):
     #    #XXX: will require root to run
     #    n = NetTest(StringIO(net_test_root_required),



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