[tor-commits] [ooni-probe/master] Add scheduler tests to ensure that lock is properly managed

art at torproject.org art at torproject.org
Fri Oct 14 19:00:56 UTC 2016


commit 2dab7a2bcaf9930ffda5a11a2b0569ca12922b18
Author: Leonid Evdokimov <leon at darkk.net.ru>
Date:   Thu Sep 29 18:52:43 2016 +0300

    Add scheduler tests to ensure that lock is properly managed
---
 ooni/tests/test_scheduler.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/ooni/tests/test_scheduler.py b/ooni/tests/test_scheduler.py
index 1350dde..a9501c0 100644
--- a/ooni/tests/test_scheduler.py
+++ b/ooni/tests/test_scheduler.py
@@ -20,6 +20,7 @@ class TestScheduler(unittest.TestCase):
         self.assertEqual(scheduled_task.should_run, True)
         self.assertFailure(scheduled_task.run(), NotImplementedError)
         self.assertEqual(scheduled_task.should_run, True)
+        self.assertFalse(os.path.islink(os.path.join(scheduler_directory, identifier + '.lock')))
         shutil.rmtree(scheduler_directory)
 
     @defer.inlineCallbacks
@@ -31,8 +32,9 @@ class TestScheduler(unittest.TestCase):
         scheduler_directory = tempfile.mkdtemp()
         spam_path = os.path.join(scheduler_directory, 'spam.txt')
         class DummyST(ScheduledTask):
-            def task(self):
-                with open(spam_path, 'w') as out_file:
+            def task(subself):
+                self.assertTrue(os.path.islink(os.path.join(scheduler_directory, subself.identifier + '.lock')))
+                with open(spam_path, 'a') as out_file:
                     out_file.write("I ran\n")
 
         schedule = "@daily"
@@ -59,6 +61,8 @@ class TestScheduler(unittest.TestCase):
 
         lock = FileSystemlockAndMutex(lock_path)
 
+        os.symlink(str(2**30), lock_path) # that's non-existend PID for sure
+
         lock_count = 100
         unlock_count = 0
         dl = []





More information about the tor-commits mailing list