Exemplo n.º 1
0
 def testlockfLock(self):
     fcntl.LOCK_FN=fcntl.lockf
     # The lockf lock is per process, so trying to get a lock from the same
     # process will always succeed
     self.assertTrue(fcntl.lock(self.lock1))
     self.assertTrue(fcntl.lock(self.lock2))
     fcntl.LOCK_FN=fcntl.flock
Exemplo n.º 2
0
    def _acquire_lock(self):
        if not self._lock_file:
            self._lock_file = open(self.config.agency.lock_path, 'rb+')
        self.debug("Trying to take a lock on %s to start the master agency",
                   self._lock_file.name)

        if fcntl.lock(self._lock_file.fileno()):
            self.debug("Lock taken sucessfully, "
                       "we will start the master agency")
            return True
        self.debug("Could not take the lock to spawn the master agency")
        return False
    def testLockAlreadyTaken(self):
        self.lock_fd = open(self.lock_path, 'rb+')
        if not fcntl.lock(self.lock_fd):
            self.fail("Could not take the lock")

        yield self.agency.initiate()
        yield self.wait_for_slave()

        pid = run.get_pid(os.path.curdir)
        run.term_pid(pid)
        yield self.wait_for_master_gone()
        yield common.delay(None, 10)
        pid = run.get_pid(os.path.curdir)
        self.assertTrue(pid is None)

        # remove the lock so that the broker in our
        # agency can connect and stop retrying, overwise the test
        # will finish in undefined way (this is part of the teardown)
        fcntl.unlock(self.lock_fd)
Exemplo n.º 4
0
 def testflockUnlockedAfterClose(self):
     self.assertTrue(fcntl.lock(self.lock1))
     self.lock1.close()
     self.lock1 = open(self.lock_path, 'rb+')
     self.assertTrue(fcntl.lock(self.lock1))
Exemplo n.º 5
0
 def testflockUnlock(self):
     self.assertTrue(fcntl.lock(self.lock1))
     self.assertFalse(fcntl.lock(self.lock2))
     self.assertTrue(fcntl.unlock(self.lock1))
     self.assertTrue(fcntl.lock(self.lock2))