From: Frank Brehm Date: Fri, 9 Mar 2018 14:39:15 +0000 (+0100) Subject: Neue test-Methoden X-Git-Tag: 0.8.4^2~9 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=63a6dfd52ba1dd446ea320f7691bc2d2590059eb;p=pixelpark%2Fpuppetmaster-webhooks.git Neue test-Methoden --- diff --git a/test/test_lock.py b/test/test_lock.py index 682f9b9..fb13dfa 100755 --- a/test/test_lock.py +++ b/test/test_lock.py @@ -100,6 +100,76 @@ class TestLockHandler(WebHooksTestcase): LOG.debug("LockHandler %%r:\n%r", locker) LOG.debug("LockHandler %%s:\n%s", str(locker)) + # ------------------------------------------------------------------------- + def test_simple_lockfile(self): + + LOG.info("Testing creation and removing of a simple lockfile.") + + from webhooks.lock_handler import LockHandler + + locker = LockHandler( + appname='test_base_object', + verbose=self.verbose, + lockdir=self.lock_dir, + ) + LOG.debug("Creating lockfile %r ...", self.lock_file) + locker.create_lockfile(self.lock_basename) + LOG.debug("Removing lockfile %r ...", self.lock_file) + locker.remove_lockfile(self.lock_basename) + + # ------------------------------------------------------------------------- + def test_lockobject(self): + + LOG.info("Testing lock object on creation of a simple lockfile.") + + from webhooks.lock_handler import LockHandler + + locker = LockHandler( + appname='test_lock', + verbose=self.verbose, + lockdir=self.lock_dir, + ) + try: + LOG.debug("Creating lockfile %r ...", self.lock_file) + lock = locker.create_lockfile(self.lock_basename) + LOG.debug("PbLock object %%r: %r", lock) + LOG.debug("PbLock object %%s: %s", str(lock)) + finally: + LOG.debug("Removing lockfile %r ...", self.lock_file) + locker.remove_lockfile(self.lock_basename) + + # ------------------------------------------------------------------------- + def test_refresh_lockobject(self): + + LOG.info("Testing refreshing of a lock object.") + + from webhooks.lock_handler import LockHandler + + locker = LockHandler( + appname='test_lock', + verbose=self.verbose, + lockdir=self.lock_dir, + ) + try: + LOG.debug("Creating lockfile %r ...", self.lock_file) + lock = locker.create_lockfile(self.lock_basename) + LOG.debug("Current ctime: %s" % (lock.ctime.isoformat(' '))) + LOG.debug("Current mtime: %s" % (lock.mtime.isoformat(' '))) + fstat1 = os.stat(lock.lockfile) + mtime1 = fstat1.st_mtime + LOG.debug("Sleeping two seconds ...") + time.sleep(2) + lock.refresh() + LOG.debug("New mtime: %s" % (lock.mtime.isoformat(' '))) + fstat2 = os.stat(lock.lockfile) + mtime2 = fstat2.st_mtime + tdiff = mtime2 - mtime1 + LOG.debug("Got a time difference between mtimes of %0.3f seconds." % (tdiff)) + self.assertGreater(mtime2, mtime1) + finally: + LOG.debug("Removing lockfile %r ...", self.lock_file) + locker.remove_lockfile(self.lock_basename) + # ============================================================================= @@ -120,6 +190,9 @@ if __name__ == '__main__': suite.addTest(TestLockHandler('test_import', verbose)) suite.addTest(TestLockHandler('test_could_not_occupy_lockfile_error', verbose)) suite.addTest(TestLockHandler('test_object', verbose)) + suite.addTest(TestLockHandler('test_simple_lockfile', verbose)) + suite.addTest(TestLockHandler('test_lockobject', verbose)) + suite.addTest(TestLockHandler('test_refresh_lockobject', verbose)) runner = unittest.TextTestRunner(verbosity=verbose)