def test_two_pids_blocking_false(self): lock_path = self._lock_path() self._grab_lock_from_other_pid(lock_path, 0.2, 1.0) b = lock.Lock(lock_path) res = b.acquire(blocking=False) self.assertFalse(b.acquired()) self.other_process.communicate("whatever".encode('utf-8')) self.assertFalse(res)
def test_lock_acquire_blocking_false(self): lock_path = self._lock_path() lf = lock.Lock(lock_path) res = lf.acquire(blocking=False) # res of False indicates lock could not be acquired without blocking # True indicates lock was acquired self.assertTrue(res)
def test_two_pids_blocking_true(self): lock_path = self._lock_path() # start a different proc that holds the lock, that times out after 3 self._grab_lock_from_other_pid(lock_path, 0.2, 1.0) b = lock.Lock(lock_path) res = b.acquire(blocking=True) self.assertTrue(b.acquired()) self.assertTrue(res)
def main(args): lock_file_path = args[1] test_lock = lock.Lock(lock_file_path) # could return a useful value, so the thread communicating with # it could notice it couldn't get the lock res = test_lock.acquire(blocking=False) if res is False: return 128 # exit on any stdin input for line in sys.stdin.readlines(): return 1
def test_two_pids_blocking_none_blocks(self): # This test will either fail occasionally, or have to wait an # unreasonable time period, which just slows down the test suite. # Left in code since it is a useful test if changing lock behavior, # but too troublesome in general. lock_path = self._lock_path() # start a different proc that holds the lock, that times out after 3 self._grab_lock_from_other_pid(lock_path, 1.0, 0.2) b = lock.Lock(lock_path) res = b.acquire() self.assertTrue(res is None)
def test_lock_acquire_stale_pid_nonblocking(self): lock_path = self._stale_lock() lf = lock.Lock(lock_path) res = lf.acquire(blocking=False) self.assertTrue(res)
def test_lock_release(self): lock_path = self._lock_path() lf = lock.Lock(lock_path) lf.acquire() lf.release()
def test_lock_acquire_blocking_true(self): lock_path = self._lock_path() lf = lock.Lock(lock_path) res = lf.acquire(blocking=True) # acquire(blocking=True) will block or return True self.assertTrue(res)
def test_lock_acquire(self): lock_path = self._lock_path() lf = lock.Lock(lock_path) res = lf.acquire() # given no args, acquire() blocks or returns None self.assertEqual(res, None)
def test_lock(self): lock_path = self._lock_path() lf = lock.Lock(lock_path) self.assertEqual(lf.path, lock_path) self.assertEqual(lf.depth, 0)
def test_lock_release(self): lf = lock.Lock("%s/lock.file" % self.tmp_dir) lf.acquire() lf.release()
def test_lock(self): lock.Lock("%s/lock.file" % self.tmp_dir)