Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
test_lock.TestExclusiveLock Class Reference

List of all members.

Public Member Functions

def setup_method
def teardown_method
def testBrokenTimeAPI
def testTimeout
def testAcquire
def testRelease
def testIsLocked
def testExists
def testIsExpired
def testExpire
def testExclusive
def testAcquireAfterTimeout
def unlock

Public Attributes

 test_dir
 test_dir_mtime_goal
 test_dir_mtime_reported
 lock_dir

Detailed Description

Definition at line 17 of file test_lock.py.


Member Function Documentation

def test_lock.TestExclusiveLock.setup_method (   self,
  method 
)

Definition at line 19 of file test_lock.py.

00019 
00020     def setup_method(self, method):
00021         self.test_dir = tempfile.mkdtemp('', 'lock_')
00022         self.test_dir_mtime_goal = time.time()
00023         self.test_dir_mtime_reported = os.stat(self.test_dir).st_mtime
00024         self.lock_dir = os.path.join(self.test_dir, "lock")

def test_lock.TestExclusiveLock.teardown_method (   self,
  method 
)

Definition at line 25 of file test_lock.py.

00025 
00026     def teardown_method(self, method):
00027         shutil.rmtree(self.test_dir)

util.lock: ExclusiveLock: acquire 

Definition at line 48 of file test_lock.py.

00048 
00049     def testAcquire(self):
00050         """ util.lock: ExclusiveLock: acquire """
00051         lock = ExclusiveLock(self.lock_dir)
00052         assert lock.acquire(0.1)

util.lock: ExclusiveLock: acquire after timeout

Lock with one lock, try to acquire another after timeout.

Definition at line 108 of file test_lock.py.

00108 
00109     def testAcquireAfterTimeout(self):
00110         """ util.lock: ExclusiveLock: acquire after timeout
00111 
00112         Lock with one lock, try to acquire another after timeout.
00113         """
00114         timeout = 2.0 # minimal timout
00115         first = ExclusiveLock(self.lock_dir, timeout)
00116         second = ExclusiveLock(self.lock_dir, timeout)
00117         if not first.acquire(0.1):
00118             py.test.skip("can't acquire lock")
00119         if second.acquire(0.1):
00120             py.test.skip("first lock is not exclusive")
00121         # Second lock should be acquired after timeout
00122         assert second.acquire(timeout + 0.1)

util.lock: os.stat().mtime consistency with time.time()

    the timestamp os.stat reports as st_mtime on a fresh file should
    be the same (or at least almost the same) as the time time.time()
    reported at this time.
    Differences of n*3600s are usually operating system bugs / limitations,
    Win32 (as of Win XP SP2 + hotfixes 2006-04-30) is broken if you set
    TZ to a different value than the rest of the system uses.
    E.g. if you set "TZ=GMT1EDT" (and the rest of the system is setup
    on german/berlin timezone), it will report 7200s difference in the
    summer.

Definition at line 28 of file test_lock.py.

00028 
00029     def testBrokenTimeAPI(self):
00030         """ util.lock: os.stat().mtime consistency with time.time()
00031 
00032             the timestamp os.stat reports as st_mtime on a fresh file should
00033             be the same (or at least almost the same) as the time time.time()
00034             reported at this time.
00035             Differences of n*3600s are usually operating system bugs / limitations,
00036             Win32 (as of Win XP SP2 + hotfixes 2006-04-30) is broken if you set
00037             TZ to a different value than the rest of the system uses.
00038             E.g. if you set "TZ=GMT1EDT" (and the rest of the system is setup
00039             on german/berlin timezone), it will report 7200s difference in the
00040             summer.
00041         """
00042         diff = self.test_dir_mtime_reported - self.test_dir_mtime_goal # diff should be 0 or near 0
00043         assert abs(diff) <= 2

util.lock: ExclusiveLock: lock is exclusive 

Definition at line 100 of file test_lock.py.

00100 
00101     def testExclusive(self):
00102         """ util.lock: ExclusiveLock: lock is exclusive """
00103         first = ExclusiveLock(self.lock_dir)
00104         second = ExclusiveLock(self.lock_dir)
00105         if not first.acquire(0.1):
00106             py.test.skip("can't acquire lock")
00107         assert not second.acquire(0.1)

util.lock: ExclusiveLock: exists 

Definition at line 73 of file test_lock.py.

00073 
00074     def testExists(self):
00075         """ util.lock: ExclusiveLock: exists """
00076         lock = ExclusiveLock(self.lock_dir)
00077         if not lock.acquire(0.1):
00078             py.test.skip("can't acquire lock")
00079         assert lock.exists()

util.lock: ExclusiveLock: expire 

Definition at line 90 of file test_lock.py.

00090 
00091     def testExpire(self):
00092         """ util.lock: ExclusiveLock: expire """
00093         timeout = 2.0
00094         lock = ExclusiveLock(self.lock_dir, timeout=timeout)
00095         if not lock.acquire(0.1):
00096             py.test.skip("can't acquire lock")
00097         assert not lock.expire()
00098         time.sleep(timeout)
00099         assert lock.expire()

util.lock: ExclusiveLock: isExpired 

Definition at line 80 of file test_lock.py.

00080 
00081     def testIsExpired(self):
00082         """ util.lock: ExclusiveLock: isExpired """
00083         timeout = 2.0
00084         lock = ExclusiveLock(self.lock_dir, timeout=timeout)
00085         if not lock.acquire(0.1):
00086             py.test.skip("can't acquire lock")
00087         assert not lock.isExpired()
00088         time.sleep(timeout)
00089         assert lock.isExpired()

util.lock: ExclusiveLock: isLocked 

Definition at line 64 of file test_lock.py.

00064 
00065     def testIsLocked(self):
00066         """ util.lock: ExclusiveLock: isLocked """
00067         lock = ExclusiveLock(self.lock_dir)
00068         if not lock.acquire(0.1):
00069             py.test.skip("can't acquire lock")
00070         assert lock.isLocked()
00071         lock.release()
00072         assert not lock.isLocked()

util.lock: ExclusiveLock: release

After releasing a lock, new one could be acquired.

Definition at line 53 of file test_lock.py.

00053 
00054     def testRelease(self):
00055         """ util.lock: ExclusiveLock: release
00056 
00057         After releasing a lock, new one could be acquired.
00058         """
00059         lock = ExclusiveLock(self.lock_dir)
00060         if not lock.acquire(0.1):
00061             py.test.skip("can't acquire lock")
00062         lock.release()
00063         assert lock.acquire(0.1)

util.lock: ExclusiveLock: raise ValueError for timeout < 2.0 

Definition at line 44 of file test_lock.py.

00044 
00045     def testTimeout(self):
00046         """ util.lock: ExclusiveLock: raise ValueError for timeout < 2.0 """
00047         py.test.raises(ValueError, ExclusiveLock, self.lock_dir, timeout=1.0)

def test_lock.TestExclusiveLock.unlock (   self,
  lock,
  delay 
)

Definition at line 123 of file test_lock.py.

00123 
00124     def unlock(self, lock, delay):
00125         time.sleep(delay)
00126         lock.release()


Member Data Documentation

Definition at line 23 of file test_lock.py.

Definition at line 20 of file test_lock.py.

Definition at line 21 of file test_lock.py.

Definition at line 22 of file test_lock.py.


The documentation for this class was generated from the following file: