Beispiel #1
0
    def testDirLock(self):
        """Lock a directory, check that lslocks sees it."""
        dirtolock = tempfile.mkdtemp()
        self.tmpdirs.append(dirtolock)
        lockproc = self._lockhelper(dirtolock)
        time.sleep(1)  # Ugly, sorry. Give flock a moment to start up.

        locks = {(pid, path.rstrip("/")) for pid, path in lslocks.lslocks(dirtolock)}
        expected_locks = {(lockproc.pid, dirtolock)}
        self.assertSetEqual(expected_locks, locks)
Beispiel #2
0
    def testFileLocks(self):
        """Lock several files, verify that lslocks finds all of them."""
        basedir = tempfile.mkdtemp()
        self.tmpdirs.append(basedir)
        locked_files = [tempfile.mkstemp(dir=basedir)[1] for _ in range(10)]
        self.tmpfiles.extend(locked_files)
        expected_locks = set()

        for tmpf in locked_files:
            proc = self._lockhelper(tmpf)
            expected_locks.add((proc.pid, tmpf.rstrip("/")))

        time.sleep(1)  # Ugly, sorry. Give flock a moment to start up.

        locks = {(pid, path.rstrip("/")) for pid, path in lslocks.lslocks(basedir)}
        self.assertSetEqual(expected_locks, locks)
Beispiel #3
0
 def testNoLocks(self):
     """Verify that it doesn't find anything when there are no locks."""
     emptydir = tempfile.mkdtemp()
     self.tmpdirs.append(emptydir)
     self.assertListEqual(list(lslocks.lslocks(emptydir)), [])