~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to landscape/lib/tests/test_lock.py

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-09-08 16:35:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080908163557-l3ixzj5dxz37wnw2
Tags: 1.0.18-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import time
 
2
import os
 
3
 
 
4
from landscape.tests.helpers import LandscapeTest
 
5
 
 
6
from landscape.lib.lock import lock_path, LockError
 
7
 
 
8
 
 
9
class LockTest(LandscapeTest):
 
10
 
 
11
    def setUp(self):
 
12
        super(LockTest, self).setUp()
 
13
        self.filename = self.makeFile()
 
14
 
 
15
    def test_lock_creates_path(self):
 
16
        self.assertFalse(os.path.isfile(self.filename))
 
17
        lock_path(self.filename)
 
18
        self.assertTrue(os.path.isfile(self.filename))
 
19
 
 
20
    def test_lock_with_already_locked(self):
 
21
        unlock_path = lock_path(self.filename)
 
22
        self.assertRaises(LockError, lock_path, self.filename)
 
23
        unlock_path()
 
24
        lock_path(self.filename)
 
25
 
 
26
    def test_lock_with_timeout(self):
 
27
        lock_path(self.filename)
 
28
        started = time.time()
 
29
        self.assertRaises(LockError, lock_path, self.filename, timeout=0.5)
 
30
        self.assertTrue(started < time.time() - 0.5)
 
31