Пример #1
0
 def test_owner_pid(self, fcntl_mock, tmpdir):
     """
     Test the get_owner_pid method. It should return the PID of the running
     process if a lock is already acquired
     """
     lock_file_path = tmpdir.join("test_lock_file1")
     # Force te lock to return a 'busy' state
     _prepare_fcntl_mock(
         fcntl_mock,
         [
             # first lock attempt: success
             None,
             # second lock attempt: failed (already locked)
             OSError(errno.EAGAIN, "", ""),
             # Unlocking the first lock
             None,
         ],
     )
     # Acquire a lock
     with LockFile(lock_file_path.strpath):
         # Create another lock and get the pid
         second_lock_file = LockFile(lock_file_path.strpath)
         pid = second_lock_file.get_owner_pid()
     # Pid should contain the current pid
     assert pid == os.getpid()
Пример #2
0
 def test_owner_pid(self, fcntl_mock, tmpdir):
     """
     Test the get_owner_pid method. It should return the PID of the running
     process if a lock is already acquired
     """
     lock_file_path = tmpdir.join("test_lock_file1")
     # Force te lock to return a 'busy' state
     _prepare_fnctl_mock(fcntl_mock, [
         # first lock attempt: success
         None,
         # second lock attempt: failed (already locked)
         OSError(errno.EAGAIN, '', ''),
         # Unlocking the first lock
         None])
     # Acquire a lock
     with LockFile(lock_file_path.strpath):
         # Create another lock and get the pid
         second_lock_file = LockFile(lock_file_path.strpath)
         pid = second_lock_file.get_owner_pid()
     # Pid should contain the current pid
     assert pid == os.getpid()